3 hours per day | Total: 12 hours
What is Artificial Intelligence? Think of AI like teaching a computer to be smart, just like how you learn new things!
The Story of AI - How It All Started:
AI vs Machine Learning vs Data Science:
Where do you see AI every day?
What is Programming? Programming is like writing a recipe for computers! Just like you follow steps to make a sandwich, computers follow our instructions (code) to do amazing things.
Why Python?
Installation Process:
First Python Program:
print("Hello, World!")
print("My name is [Your Name]")
print("I'm learning Python and AI!")Hands-on Activity:
Variables - Computer's Memory Boxes Think of variables like labeled boxes where you store different things:
# Numbers (integers)
age = 12
favorite_number = 7
# Decimal numbers (floats)
height = 4.5
temperature = 98.6
# Text (strings)
name = "Alex"
favorite_color = "blue"
# True or False (booleans)
likes_pizza = True
is_raining = FalseInteractive Examples:
# Let's make a simple profile
student_name = input("What's your name? ")
student_age = int(input("How old are you? "))
favorite_subject = input("What's your favorite subject? ")
print(f"Hi {student_name}!")
print(f"You are {student_age} years old")
print(f"Your favorite subject is {favorite_subject}")Exercises:
Real-life Decision Making: Every day you make decisions: "If it's raining, I'll take an umbrella. Otherwise, I won't."
Python Decision Making:
# Simple if statement
weather = input("How's the weather? (sunny/rainy): ")
if weather == "rainy":
print("Take an umbrella! โ๏ธ")
elif weather == "sunny":
print("Wear sunglasses! ๐")
else:
print("Check the weather again!")Number Guessing Game:
import random
secret_number = random.randint(1, 10)
guess = int(input("Guess a number between 1 and 10: "))
if guess == secret_number:
print("๐ Amazing! You got it right!")
elif guess < secret_number:
print("๐ Too low! The number was", secret_number)
else:
print("๐ Too high! The number was", secret_number)Exercises:
Why do we need loops? Imagine writing "I will practice Python" 100 times by hand - loops save us time!
For Loops - Counting Adventures:
# Print numbers 1 to 5
for number in range(1, 6):
print(f"Count: {number}")
# Print your name 3 times with decoration
for i in range(3):
print(f"โญ My name is Alex โญ")
# Create a multiplication table
number = 5
for i in range(1, 11):
print(f"{number} x {i} = {number * i}")While Loops - Keep Going Until...
# Countdown game
countdown = 5
print("Rocket launch countdown:")
while countdown > 0:
print(f"{countdown}...")
countdown -= 1
print("๐ BLAST OFF!")
# Keep asking until correct answer
correct_answer = "python"
while True:
answer = input("What programming language are we learning? ").lower()
if answer == correct_answer:
print("Correct! ๐")
break
else:
print("Try again!")Understanding Errors - Don't Be Scared! Errors are like spelling mistakes - they help us learn and improve!
Common Error Types:
# Syntax Error - like forgetting punctuation
# print("Hello World" # Missing closing parenthesis
# Runtime Error - happens while program runs
try:
age = int(input("Enter your age: "))
next_year_age = age + 1
print(f"Next year you'll be {next_year_age}")
except ValueError:
print("Please enter a valid number!")Pattern Creation with Loops:
# Create a star triangle
rows = 5
for i in range(1, rows + 1):
print("โญ" * i)
# Create a number pyramid
for i in range(1, 6):
spaces = " " * (5 - i)
numbers = str(i) * (2 * i - 1)
print(spaces + numbers)Exercises:
What are Functions? Functions are like having helpful robots that do specific jobs for you!
Creating Your First Functions:
# Simple greeting function
def say_hello(name):
return f"Hello, {name}! Welcome to Python! ๐"
# Function that calculates something
def calculate_age_in_days(age_in_years):
days = age_in_years * 365
return days
# Function with multiple parameters
def introduce_student(name, age, grade):
introduction = f"Hi! I'm {name}, I'm {age} years old and in grade {grade}"
return introduction
# Using our functions
student_name = "Sarah"
greeting = say_hello(student_name)
print(greeting)
age = 13
days_alive = calculate_age_in_days(age)
print(f"You've been alive for approximately {days_alive} days!")Building a Calculator with Functions:
def add_numbers(num1, num2):
return num1 + num2
def subtract_numbers(num1, num2):
return num1 - num2
def multiply_numbers(num1, num2):
return num1 * num2
def divide_numbers(num1, num2):
if num2 != 0:
return num1 / num2
else:
return "Can't divide by zero!"
# Simple calculator interface
print("๐งฎ Welcome to My Calculator!")
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
print(f"{a} + {b} = {add_numbers(a, b)}")
print(f"{a} - {b} = {subtract_numbers(a, b)}")
print(f"{a} ร {b} = {multiply_numbers(a, b)}")
print(f"{a} รท {b} = {divide_numbers(a, b)}")Lists - Your Digital Backpack:
# Creating lists
favorite_foods = ["pizza", "ice cream", "burgers", "tacos"]
lucky_numbers = [7, 13, 21, 42]
mixed_list = ["Alice", 14, True, 3.14]
# Working with lists
print("My favorite foods:")
for food in favorite_foods:
print(f"- {food}")
# Adding and removing items
favorite_foods.append("chocolate") # Add to end
favorite_foods.insert(0, "pasta") # Add to beginning
removed_food = favorite_foods.pop() # Remove from end
print(f"I removed {removed_food} from my list")
# List methods
print(f"I have {len(favorite_foods)} favorite foods")
if "pizza" in favorite_foods:
print("Pizza is still my favorite! ๐")Tuples - Lists That Don't Change:
# Coordinates that shouldn't change
home_location = (40.7128, -74.0060) # New York coordinates
birthday = (15, "March", 2010) # Day, Month, Year
# RGB color values
red_color = (255, 0, 0)
blue_color = (0, 0, 255)
print(f"My birthday is {birthday[0]} {birthday[1]}, {birthday[2]}")Fun List Activities:
# Random name picker
import random
students = ["Alex", "Sam", "Jordan", "Casey", "Riley"]
chosen_student = random.choice(students)
print(f"Today's helper is {chosen_student}! ๐")
# Grade tracker
grades = []
while True:
grade = input("Enter a grade (or 'done' to finish): ")
if grade.lower() == 'done':
break
grades.append(int(grade))
if grades:
average = sum(grades) / len(grades)
print(f"Your average grade is: {average:.1f}")Dictionaries - Like a Real Dictionary:
# Student information
student_info = {
"name": "Emma",
"age": 14,
"grade": 8,
"favorite_subjects": ["Math", "Science", "Art"],
"has_pet": True
}
# Accessing information
print(f"Student name: {student_info['name']}")
print(f"Age: {student_info['age']}")
print(f"Favorite subjects: {student_info['favorite_subjects']}")
# Phone book example
phone_book = {
"Mom": "555-0123",
"Dad": "555-0124",
"Best Friend": "555-0125",
"Pizza Place": "555-PIZZA"
}
# Adding new entries
phone_book["School"] = "555-0100"Inventory Management Game:
# Game inventory system
player_inventory = {
"coins": 50,
"health_potions": 3,
"magic_sword": 1,
"keys": 2
}
def show_inventory():
print("\n๐ Your Inventory:")
for item, quantity in player_inventory.items():
print(f" {item}: {quantity}")
def use_item(item_name):
if item_name in player_inventory and player_inventory[item_name] > 0:
player_inventory[item_name] -= 1
print(f"Used {item_name}!")
else:
print(f"You don't have any {item_name}")
show_inventory()
use_item("health_potions")
show_inventory()Sets - Collections of Unique Items:
# Sets automatically remove duplicates
favorite_colors = {"red", "blue", "green", "blue", "red"}
print(favorite_colors) # Only shows unique colors
# Useful set operations
class_a_students = {"Alice", "Bob", "Charlie", "David"}
class_b_students = {"Charlie", "David", "Eve", "Frank"}
# Students in both classes
both_classes = class_a_students & class_b_students
print(f"Students in both classes: {both_classes}")
# All students
all_students = class_a_students | class_b_students
print(f"All students: {all_students}")What is an Object? Look around you - everything is an object! Your phone, your pet, even you are objects with properties and abilities.
Real-Life Object Examples:
Your First Class:
# Creating a Pet class
class Pet:
def __init__(self, name, species, age):
self.name = name # Property
self.species = species
self.age = age
self.happiness = 50 # Default happiness level
self.energy = 100 # Default energy level
def make_sound(self): # Method (action)
if self.species == "dog":
return f"{self.name} says Woof! ๐"
elif self.species == "cat":
return f"{self.name} says Meow! ๐ฑ"
else:
return f"{self.name} makes a sound! ๐พ"
def play(self):
if self.energy >= 20:
self.happiness += 10
self.energy -= 20
return f"{self.name} is playing! Happiness: {self.happiness}"
else:
return f"{self.name} is too tired to play!"
def feed(self):
self.energy += 30
self.happiness += 5
return f"{self.name} is eating! Energy: {self.energy}"
# Creating pet objects
my_dog = Pet("Buddy", "dog", 3)
my_cat = Pet("Whiskers", "cat", 2)
# Using our pets
print(my_dog.make_sound())
print(my_cat.make_sound())
print(my_dog.play())
print(my_cat.feed())Creating a Student Class:
class Student:
def __init__(self, name, age, grade):
self.name = name
self.age = age
self.grade = grade
self.subjects = []
self.grades = {}
self.attendance = 0
def add_subject(self, subject):
if subject not in self.subjects:
self.subjects.append(subject)
self.grades[subject] = []
print(f"Added {subject} to {self.name}'s subjects")
def add_grade(self, subject, grade):
if subject in self.subjects:
self.grades[subject].append(grade)
print(f"Added grade {grade} for {subject}")
else:
print(f"{self.name} is not enrolled in {subject}")
def calculate_average(self, subject):
if subject in self.grades and self.grades[subject]:
return sum(self.grades[subject]) / len(self.grades[subject])
return 0
def get_overall_average(self):
all_grades = []
for subject_grades in self.grades.values():
all_grades.extend(subject_grades)
if all_grades:
return sum(all_grades) / len(all_grades)
return 0
def show_report_card(self):
print(f"\n๐ Report Card for {self.name}")
print(f"Age: {self.age}, Grade: {self.grade}")
print("Subject Averages:")
for subject in self.subjects:
avg = self.calculate_average(subject)
print(f" {subject}: {avg:.1f}")
overall = self.get_overall_average()
print(f"Overall Average: {overall:.1f}")
# Using the Student class
alice = Student("Alice", 13, 8)
alice.add_subject("Math")
alice.add_subject("Science")
alice.add_subject("English")
alice.add_grade("Math", 85)
alice.add_grade("Math", 92)
alice.add_grade("Science", 78)
alice.add_grade("Science", 88)
alice.add_grade("English", 95)
alice.show_report_card()Understanding Inheritance: Just like you inherit traits from your parents, classes can inherit from other classes!
Animal Family Tree:
# Parent class (Base class)
class Animal:
def __init__(self, name, species):
self.name = name
self.species = species
self.energy = 100
def eat(self):
self.energy += 20
return f"{self.name} is eating and gained energy!"
def sleep(self):
self.energy = 100
return f"{self.name} is sleeping and restored energy!"
def make_sound(self):
return f"{self.name} makes a generic animal sound"
# Child classes (Inherited classes)
class Dog(Animal):
def __init__(self, name, breed):
super().__init__(name, "Dog") # Call parent constructor
self.breed = breed
self.tricks = []
def make_sound(self): # Override parent method
return f"{self.name} barks: Woof! Woof! ๐"
def learn_trick(self, trick):
self.tricks.append(trick)
return f"{self.name} learned {trick}!"
def perform_trick(self):
if self.tricks:
trick = self.tricks[-1] # Latest trick
return f"{self.name} performs {trick}! ๐ช"
return f"{self.name} doesn't know any tricks yet"
class Cat(Animal):
def __init__(self, name, color):
super().__init__(name, "Cat")
self.color = color
self.lives = 9
def make_sound(self): # Override parent method
return f"{self.name} meows: Meow! Purr! ๐ฑ"
def climb(self):
if self.energy >= 30:
self.energy -= 30
return f"{self.name} climbs up high! ๐ณ"
return f"{self.name} is too tired to climb"
class Bird(Animal):
def __init__(self, name, wing_span):
super().__init__(name, "Bird")
self.wing_span = wing_span
self.can_fly = True
def make_sound(self):
return f"{self.name} chirps: Tweet! Tweet! ๐ฆ"
def fly(self):
if self.energy >= 40 and self.can_fly:
self.energy -= 40
return f"{self.name} soars through the sky! โ๏ธ"
return f"{self.name} can't fly right now"
# Creating our animal family
buddy = Dog("Buddy", "Golden Retriever")
whiskers = Cat("Whiskers", "Orange")
tweety = Bird("Tweety", "Small")
# Testing our animals
print(buddy.make_sound())
print(buddy.learn_trick("sit"))
print(buddy.learn_trick("roll over"))
print(buddy.perform_trick())
print()
print(whiskers.make_sound())
print(whiskers.climb())
print()
print(tweety.make_sound())
print(tweety.fly())Final Project - Virtual Pet Game:
class VirtualPet:
def __init__(self, name, pet_type):
self.name = name
self.pet_type = pet_type
self.happiness = 50
self.hunger = 50
self.energy = 100
self.age = 0
def status(self):
print(f"\n๐พ {self.name} the {self.pet_type}")
print(f"Happiness: {self.happiness}/100")
print(f"Hunger: {self.hunger}/100")
print(f"Energy: {self.energy}/100")
print(f"Age: {self.age} days")
def feed(self):
self.hunger = max(0, self.hunger - 30)
self.happiness += 10
print(f"{self.name} enjoyed the meal! ๐ฝ๏ธ")
def play(self):
if self.energy >= 20:
self.energy -= 20
self.happiness += 20
self.hunger += 10
print(f"{self.name} had fun playing! ๐พ")
else:
print(f"{self.name} is too tired to play!")
def sleep(self):
self.energy = 100
self.age += 1
self.hunger += 15
print(f"{self.name} had a good rest! ๐ด")
# Game loop
def pet_game():
name = input("What would you like to name your pet? ")
pet_type = input("What type of pet? (dog/cat/bird): ")
my_pet = VirtualPet(name, pet_type)
while True:
my_pet.status()
print("\nWhat would you like to do?")
print("1. Feed pet")
print("2. Play with pet")
print("3. Let pet sleep")
print("4. Quit game")
choice = input("Enter your choice (1-4): ")
if choice == "1":
my_pet.feed()
elif choice == "2":
my_pet.play()
elif choice == "3":
my_pet.sleep()
elif choice == "4":
print(f"Goodbye! Take care of {my_pet.name}! ๐")
break
else:
print("Invalid choice! Try again.")
# Uncomment to play the game
# pet_game()Final Day Celebration:
Take-Home Projects:
Next Steps:
Remember: The key to teaching children is patience, encouragement, and making coding fun! Every small success should be celebrated, and every error should be treated as a learning opportunity. ๐