INTRODUCTION TO
DATA TYPES
Creative Technologies 8
Data
◦Fundamental to the operation of
computers and software programs. It
consists of raw facts or values that a
program can process and manipulate.
Types of Data
◦Integers
◦Floats
◦Strings
◦Booleans
Integers
◦Are whole numbers, both positive and negative including zero
◦They don’t have any fractional or decimal parts
◦Commonly used un programs when you need to count items,
track quantities, or deal with things like age, days, or steps .
Example of Integer Values:
Positive integers- 5, 10, 100
Negative integers- -3, -42
Zero- 0
Counting the number of items in a shopping cart
Storing number of people in a room
Floats
◦Represent numbers that have a decimal point or express in
scientific notation
◦Used when precision is needed, such as in calculations involving
measurements or financial data where decimals matter.
measuring height, weight, or temperature
Calculating average scores or prices
performing financial computations
Examples of Float values:
3.14 (approximation of pi)
7.5 (weight of kilograms)
-0.5 (negative temperature values)
Strings
◦are sequences of characters, and they can be made up of
letters, numbers, symbols, and spaces.
◦used to store textual information like names, addresses,
messages, or any non-numeric data.
Storing user input like names, addresses, or email addresses.
Working with files or documents that contain text.
Examples:
Hello, World!“ "John Doe“ "123 Main Street"
Booleans
◦A Boolean is a data type that can only have one of two
possible values: True or False.
◦This type is used for decision-making processes, where the
program needs to check conditions and make choices based
on whether those conditions are true or false.
Verifying if a user is logged in (True or False).
Checking if a number is positive or negative.
Validating whether a form field has been filled correctly.
Group activity
“Data Type Relay Race”
The game will consist of rounds where each team races to
categorize the examples into one of the four data types
(integers, floats, strings, Booleans)
For each round, 1 player from each team runs up to the board
and writes the correct classification of the given examples.
The first team to correctly categorize all examples wins the
game.
“apple” -1 150.75 True
False 0.99 “Welcome, to the game!”
(4==4)=
0 2024 “hello” 3.14 True
(5>3)= -12 0.333333
True “STE”
-8
Bye 5.5555 (10 < 5)= false
CONSTANTS &
VARIABLES
Creative Technologies 8
Variables
◦Is like a container that HOLDS a data. The data inside
a variable can CHANGE.
◦E.g. if you are keeping track of your score in a game,
it might change every time you get points.
Constants
◦Is like a special variable that CANNOT CHANGE. It holds FIXED
value, such as value of pi in math.
◦Example:
Variable: Play Score (could be change as the player score points)
Constants: Maximum Lives= 3 (the number of lives doesn’t change during
the game)
◦Using variables gives your program flexibility,
allowing you to work with values that can
change.
◦Using constants makes your code more
predictable and reduces errors, as certain
values (like the number of players) are meant
to stay the same throughout the program.
LIST AND
DICTIONARIES
Creative Technologies 8
What is a LIST?
A list is used to store a collection of items. The items can be
numbers, text or other types of data. List are ordered, which
means each item has a position.
Ex.
Fruits = apple, banana, cherry
What is a DICTIONARY?
◦A dictionary stores data as key- value pairs. Each key is unique
and maps to a value. This is useful when we want to store
related information, like a person’s name and age.
◦Ex.
Student Info= Name: Alice
Age: 25
Address: Lapuyan, ZDS
Examples
LIST (if we want to store a list of colors)
Colors= Red, Blue, Green, Yellow
DICTIONARIES (if we want to store a student’s name and grade)
Student Grade= Name: Chloe Indus
Section: STE
Grade: 95
List vs. Dictionary
◦List store ordered data while dictionaries
store data with labels
Activity!
◦ Create a list of 5- 10 of your favorite foods. Include the name of the food
and if possible, a brief description why it’s your favorite or memory
associated with it.
◦ Create a dictionary with your name, age, and a few fun facts about
yourself. You can include your
name, age, favorite subject, a hobby you enjoy, place you’d love to
visit, etc.
make sure each piece of information is labeled with a key in the
dictionary.
Example
STORING DATA IN
FILES
Creative Technologies 8
Why store Data in files?
◦Storing data in a file allows you to keep it
even after the program ends. For
example, you can save game scores or
user preferences.
◦When a program is running, it uses memory
(RAM) to temporarily store data. But when
program stops, that data is lost. To save this
data permanently, we write the files stored on
a disk (like a hard drive). These files can the be
reopened and used later.
Why uses files to store data?
◦Persistence
◦Sharing
◦Analysis and reuse
Types of Files
◦Text Files:
Store data as plain text
Easy to read and write
Ex. Name, age, city, Angelica, 25, New York, Bob, 30, London
◦Binary Files:
Store data in compact binary format
Cannot be easily read without specialized tools or programs
Used for images, videos, or program-specific data
How storing data works?
◦Writing Data to a File
open a file to store a data
write the data into the file
close the file to save the changes
◦Reading Data from a File
Open the file in read mode
Load the data from the file
use the data in your program