Lesson 1

🔢 Python Numbers - Types of Numbers

Learn about the three types of numbers in Python!

📖 What are Number Types?

In Python, numbers come in three special types! Just like you have whole apples, half apples, or imaginary things, Python has different types for different kinds of numbers.

1. Integer (int) - Whole Numbers 🍎

Integers are whole numbers with no decimals. They can be positive, negative, or zero!

age = 12 # Integer
temperature = -5 # Negative integer
score = 0 # Zero is also an integer
big_number = 1000000 # Big integers work too!

2. Float - Decimal Numbers 🍰

Floats are numbers with decimal points. Perfect for measurements!

height = 1.55 # Float with decimals
pi = 3.14159 # Famous math number!
price = 9.99 # Money values

3. Complex - Super Special Numbers 🌟

Complex numbers use "j" for imaginary parts. You'll learn more about these in advanced math!

x = 3+5j # Complex number
y = 2j # Just imaginary part

Checking Number Types 🔍

Use type() to see what type a number is:

print(type(10)) # <class 'int'>
print(type(10.5)) # <class 'float'>
print(type(1j)) # <class 'complex'>

🎯 Quick Quiz

Question: What type is the number 3.14?

💻 Try It Yourself!

Create three variables: one integer, one float, and use type() to check them!

✍️ Code Editor
Lesson 2

🔄 Python Casting - Converting Types

Learn how to change one type to another!

📖 What is Casting?

Casting is like a magic spell that changes one type into another! Sometimes you need a number as text, or text as a number.

int() - Make it a Whole Number 🎯

Converts to integer (whole number):

x = int(5.9) # x becomes 5 (removes decimal)
y = int("10") # y becomes 10 (from text)
print(x, y) # Shows: 5 10

float() - Make it a Decimal 🎈

Converts to float (decimal number):

x = float(5) # x becomes 5.0
y = float("3.14") # y becomes 3.14
print(x, y) # Shows: 5.0 3.14

str() - Make it Text 📝

Converts to string (text):

x = str(100) # x becomes "100" (text)
y = str(3.14) # y becomes "3.14" (text)
print("Score: " + x) # Now we can add it to text!

Why Casting Matters? 🤔

Sometimes you can't mix types. Casting helps you fix that!

# This causes ERROR:
# print("Age: " + 12)
# This works perfectly!
print("Age: " + str(12)) # Shows: Age: 12

🎯 Quick Quiz

Question: What does int(7.8) give you?

💻 Try It Yourself!

Convert 3.99 to an integer and "25" to a number, then add them!

✍️ Code Editor
Lesson 3

⚙️ Python Operators - Introduction

Learn about operators and what they do!

📖 What are Operators?

Operators are special symbols that tell Python to do something with values. Like + for adding or = for saving!

Types of Operators 🎨

Python has different groups of operators:

  • Arithmetic Operators - Math stuff like +, -, *, /
  • Assignment Operators - Saving values like =, +=, -=
  • Comparison Operators - Comparing things like ==, >, << /li>
  • Logical Operators - Logic like and, or, not

Simple Examples 🌟

# Arithmetic (Math)
result = 10 + 5 # Addition
# Assignment (Saving)
x = 5 # Save 5 in x
# Comparison (Checking)
print(10 > 5) # Shows: True

Why Operators are Important 💡

Operators let you:

  • Calculate math problems 🧮
  • Store and update values 💾
  • Compare numbers and make decisions 🤔
  • Build logic in your programs 🧠

🎯 Quick Quiz

Question: Which operator is used for addition?

💻 Try It Yourself!

Use different operators: add two numbers, save a value, and compare two values!

✍️ Code Editor
Lesson 4

➕ Arithmetic Operators - Math Power!

Master all the math operators in Python!

📖 Arithmetic Operators

These operators let you do math! Python is like a super calculator! 🧮

The Basic Four ➕ ➖ ✖️ ➗

print(10 + 3) # Addition = 13
print(10 - 3) # Subtraction = 7
print(10 * 3) # Multiplication = 30
print(10 / 3) # Division = 3.333...

Special Math Operators 🌟

# Floor Division - Divide and round down
print(10 // 3) # Shows: 3 (no decimals!)
# Modulus - Get the remainder
print(10 % 3) # Shows: 1 (what's left over)
# Exponent - Power!
print(2 ** 3) # Shows: 8 (2×2×2)

Real Life Examples 🎮

# Splitting pizza among friends
slices = 8
friends = 3
slices_each = slices // friends # Each gets 2 slices
leftover = slices % friends # 2 slices left!
print("Each friend gets:", slices_each)
print("Leftover slices:", leftover)

Order Matters! 🎯

Python follows math rules (PEMDAS):

print(2 + 3 * 4) # Shows: 14 (not 20!)
print((2 + 3) * 4) # Shows: 20 (parentheses first!)

🎯 Quick Quiz

Question: What does 15 % 4 give you?

💻 Try It Yourself!

Calculate: 2 to the power of 5, then divide 20 by 3 using floor division!

✍️ Code Editor
Lesson 5

📝 Assignment Operators - Smart Shortcuts!

Learn quick ways to update variables!

📖 Assignment Operators

These operators help you update variables faster! They're like shortcuts! ⚡

Regular Assignment =

The = operator saves a value:

score = 100 # Give score the value 100

Addition Assignment +=

Add to the current value:

score = 100
score += 10 # Same as: score = score + 10
print(score) # Shows: 110

All the Shortcuts! ⚡

x = 20
x += 5 # Add 5 → x is now 25
x -= 3 # Subtract 3 → x is now 22
x *= 2 # Multiply by 2 → x is now 44
x /= 4 # Divide by 4 → x is now 11.0
x //= 2 # Floor divide by 2 → x is now 5.0
x %= 3 # Modulus 3 → x is now 2.0
x **= 3 # Power of 3 → x is now 8.0

Real Example: Game Score 🎮

score = 0
print("Game started!")
score += 50 # Collected coin!
print("Score:", score) # Shows: 50
score += 100 # Defeated enemy!
print("Score:", score) # Shows: 150
score *= 2 # Double points power-up!
print("Final Score:", score) # Shows: 300

🎯 Quiz

Question: If x = 10, what is x after running x += 5?

💻 Try It Yourself!

Start with points = 100, add 50, then multiply by 2!

✍️ Code Editor
Lesson 6

⚖️ Comparison Operators - Compare Values!

Learn how to compare numbers and values!

📖 Comparison Operators

These operators compare two values and give you True or False! Like asking questions! 🤔

Equal To ==

Checks if two values are the same:

print(5 == 5) # True
print(5 == 3) # False

Not Equal To !=

Checks if two values are different:

print(5 != 3) # True (they're different!)
print(5 != 5) # False (they're the same)

Greater and Lesser 🎯

print(10 > 5) # True (10 is greater)
print(5 > 10) # False
print(3 < 7) # True (3 is less than 7)
print(7 < 3) # False

Greater or Equal, Less or Equal ≥ ≤

print(10 >= 10) # True (equal counts!)
print(10 >= 5) # True (greater also counts!)
print(5 <= 5) # True
print(3 <= 7) # True

Real Example: Age Check 🎂

my_age = 12
minimum_age = 13
can_play = my_age >= minimum_age
print("Can play game:", can_play) # Shows: False

Important! ⚠️

  • Use == to compare (two equals signs!)
  • Use = to assign (one equals sign!)
  • Don't mix them up!

🎯 Quick Quiz

Question: What does 7 < 10 give you?

💻 Try It Yourself!

Compare: Is 15 greater than or equal to 10? Is 8 equal to 9?

✍️ Code Editor
Lesson 7

🤔 Python Conditions - Make Decisions!

Learn how to make your code smart with if statements!

📖 What are Conditions?

Conditions let your code make decisions! Like "IF it's raining, THEN bring an umbrella!" ☔

The if Statement 🎯

Run code ONLY if something is true:

age = 12
if age >= 10:
print("You can play this game!")
# This will print because 12 >= 10 is True!

The else Statement 🔄

Do something ELSE if the condition is false:

score = 45
if score >= 50:
print("You passed!")
else:
print("Try again!")
# Shows: Try again! (because 45 < 50)

The elif Statement 🎨

Check multiple conditions! (elif = else if)

score = 75
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C")
else:
print("Grade: D")
# Shows: Grade: C

Important: Indentation! ⚠️

Python uses spaces/tabs to know what's inside the if block!

if 5 > 3:
print("This is indented") # Inside the if
print("This too!") # Also inside
print("This always runs") # Outside the if

Real Example: Weather Check 🌤️

temperature = 25
if temperature > 30:
print("It's hot! 🌞")
elif temperature > 20:
print("Perfect weather! 😊")
elif temperature > 10:
print("A bit cold! 🧥")
else:
print("It's freezing! ❄️")

🎯 Quick Quiz

Question: What keyword do you use for "else if"?

💻 Try It Yourself!

Write a program that checks if a number is positive, negative, or zero!

✍️ Code Editor