1 / 24
Programming · Grade 7 · Chapter 4

Data Types & Operators

Storing, categorizing, and performing operations on data in Python.

Chapter Goals

What We Will Master Today

The Memory Box

How Does Python Remember Information?

In video games, your score increases, player health decreases, and high scores save automatically. Where do these numbers live?

Concept: A variable is a labeled memory container inside your computer's RAM.
Core Concept 1

Creating Variables (Assignment =)

In Python, we create a variable by giving it a name and assigning it a value using =.

player_name = "Alex" # String variable
score = 150 # Integer variable
health = 98.5 # Float variable
is_alive = True # Boolean variable
Rulebook

Python Variable Naming Rules

✓ Valid Names (snake_case)

player_score = 10

user_2 = "Maya"

_secret_key = "x99"

✗ Invalid Names (SyntaxError)

2nd_user = "Maya" (starts with number)

player score = 10 (contains space)

class = 7 (reserved keyword)

Core Concept 2

The 4 Core Data Types in Python

str

String

Text enclosed in quotes.
"Hello"

int

Integer

Whole numbers without decimals.
42, -7

float

Float

Decimal / floating-point numbers.
3.14, 0.5

bool

Boolean

Truth values.
True or False

Built-in Function

Checking Data Types with type()

print(type("Grade 7")) # Outputs: <class 'str'>
print(type(100)) # Outputs: <class 'int'>
print(type(9.99)) # Outputs: <class 'float'>
print(type(True)) # Outputs: <class 'bool'>
Core Concept 3

Python Arithmetic Operators

Standard Math

+ Addition (5 + 3 = 8)

- Subtraction (10 - 4 = 6)

* Multiplication (4 * 3 = 12)

/ Division (7 / 2 = 3.5)

Special Operators

// Floor Division (7 // 2 = 3)

% Modulo Remainder (7 % 2 = 1)

** Exponentiation (2 ** 3 = 8)

Deep Dive

Understanding Floor Division // and Modulo %

Imagine dividing 17 cookies equally among 5 friends:

17 // 5
= 3 cookies per friend (Whole quotient)
17 % 5
= 2 cookies left over in jar (Remainder)
Modulo % 2 is frequently used in coding to check if a number is Even (0) or Odd (1)!
Math Sandbox

Predict the Output of These Operations!

a = 20 % 6 # What is 20 divided by 6 remainder?
b = 20 // 6 # What is whole part of 20 / 6?
c = 3 ** 3 # What is 3 to the power of 3?

print(a, b, c) # Output?
Core Concept 4

String Operations: Concatenation & Multiplication

# 1. Concatenation (+) joins strings together
first = "Super"
second = "Mario"
full_name = first + " " + second # Outputs: "Super Mario"

# 2. String Repetition (*) repeats text
banner = "=" * 10 # Outputs: "=========="
Trap Alert

"10" + "5" is NOT 15!

String Concatenation

print("10" + "5")

Output: "105" (Glued together)

Integer Math

print(10 + 5)

Output: 15 (Numeric addition)
Core Concept 5

Type Casting (Converting Data Types)

We use functions like int(), float(), and str() to change a value's data type.

age_text = "13" # str
age_num = int(age_text) # Converted to int 13

price = 19.99 # float
price_int = int(price) # Drops decimal -> 19

score = 100 # int
score_str = str(score) # Converted to str "100"
User Input

Casting User Input

The input() function ALWAYS returns data as a String. To do math, you must cast it!

# Asking user for age:
user_age = input("Enter your age: ") # returns "13" (str)
next_year = int(user_age) + 1 # 13 + 1 = 14
print("Next year you will be " + str(next_year))
Spot the Mistake

Can You Fix This TypeError?

# Broken script:
score = 100
print("Your total score is: " + score)

TypeError: can only concatenate str (not "int") to str
Fix: Wrap score inside str(score) so string addition works!
Smartboard Voting

Identify the Data Type!

Value 1

"3.14"

(Is it float or str?)

Value 2

5 == 5

(Is it int or bool?)

Value 3

10 / 2

(Is it int or float?)
Quick Check · Quiz 1

What is the result of 15 % 4 in Python?

A3.75
B3
C3 (Remainder)
D0
Click to reveal answer
Quick Check · Quiz 2

Which of the following is a valid variable name in Python?

A1st_score
Buser name
Ctotal_score_2
Dclass
Click to reveal answer
Quick Check · Quiz 3

What data type does division / ALWAYS produce in Python 3?

Aint
Bfloat
Cstr
Dbool
Click to reveal answer
Quick Check · Quiz 4

What will "Go!" * 3 produce in Python?

AError
B"Go!Go!Go!"
C"Go! 3"
D"Go!Go!"
Click to reveal answer
Guided Practice

Build a Shopping Receipt Calculator

item_price = 12.50
quantity = 4
subtotal = item_price * quantity
tax = subtotal * 0.10
total = subtotal + tax

print("Final Bill: $" + str(total))
Variable Flexibility

Variable Reassignment in Python

A variable can be updated to store a new value at any point in the program!

count = 1 # count is 1
count = count + 1 # count is now 2
count = "Done" # count is now a String "Done"
Summary & Takeaways

What We Learned in Chapter 4

Exit Ticket

Data Type Matching Challenge

Write on your ticket:

1. Data type of "Grade 7"

2. Output of 19 // 5

3. Output of 19 % 5

Next Chapter: How AI Models Work!