Python
Crash Course
for Kids
Breakdown
Day 1: Welcome to Python Land!
Day 2: Python Superpowers – Variables and Inputs!
Day 3: Decision Time – Python Style!
Day 4: Loops and Lists – Coding Like a Gamer!
Day 5: Coding Showdown – Mini-Project Day!
Collection Data Types
• Collection data types in Python are used to store
multiple items in a single variable.
• They are particularly useful when you need to work
with, manipulate, or organize large amounts of data.
1. List (A Collection of Items)
2. Dictionary (Key-Value Pairs)
List
• A list stores multiple items in one variable, like a shopping list or favorite movies.
• They are denoted by square brackets []
fruits = ["apple", "banana", "cherry"]
• Each item in a list is assigned a specific position or index, which starts from 0 for the
first item, 1 for the second, and so on.
• You can use these indexes to extract specific items directly.
• Print the first item from a list:
print ("The first fruit is " + fruits[0])
Python’s Built-in Functions for Lists
✓ len(): Counts items in the list.
✓ .append(): Adds an item to the end.
✓ .remove(): Removes an item.
✓ .pop(): Removes and returns the last item.
✓ sorted(): Returns a sorted version of the list.
Python’s Built-in Functions for Lists
• Example:
fruits = ["apple", "banana", "cherry"]
print (len(fruits)) # Output: 3
fruits.append("orange")
print (fruits) # Output: ['apple', 'banana', 'cherry', 'orange']
fruits.remove("banana")
print (fruits) # Output: ['apple', 'cherry', 'orange’]
print (sorted(fruits)) # Output: ['apple', 'cherry', 'orange']
Dictionary
• A dictionary holds items in pairs, like a phone book or a word and its definition.
• They are denoted by curly braces {}, with key-value pairs separated by colons :
superhero = {"name": "Spiderman", "power": "web-slinging"}
• Access specific information:
print (superhero["name"] + " has the power of " + superhero["power"] + ".")
Python’s Built-in Functions for Dictionary
✓ len(): Counts items in the dictionary.
✓ .keys(): Returns a list of keys.
✓ .values(): Returns a list of values.
✓ .items(): Returns both keys and values.
✓ .get(): Gets the value of a key.
Python’s Built-in Functions for Dictionary
• Example:
superhero = {"name": "Spiderman", "power": "web-slinging", "age": 16}
print (len(superhero)) # Output: 3
print (superhero.keys()) # Output: dict_keys(['name', 'power', 'age’])
print (superhero.values()) # Output: dict_values(['Spiderman', 'web-slinging', 16])
print (superhero.get("power")) # Output: web-slinging
Naming Conventions for Variable Names
• Start with a Letter or Underscore (_):
Variables cannot begin with a number or special character.
age
_name
1value
• Use Alphanumeric Characters and Underscores:
Variable names can only include letters (A-Z, a-z), numbers (0-9), and underscores (_).
student_name
total_marks
name@age
Naming Conventions for Variable Names
• Avoid Reserved Keywords:
Python keywords like if, else, True, and class cannot be used as variable names.
student_id
class
• Words in the name should be lowercase and separated by underscores for readability.
student_name
total_cost
StudentName (reserved for classes)
Naming Conventions for Variable Names
• Meaningful and Descriptive Names
Choose names that clearly describe the variable's purpose.
user_age
average_score
x, temp (Avoid vague names unless used in short loops or quick calculations).
• Constants in UPPERCASE
If a variable is meant to remain unchanged, use all uppercase letters with underscores.
PI = 3.14159
MAX_LIMIT = 100
Inputs and Outputs
• Taking input from users with input()
name = input("What's your name? ")
print ("Hi, " + name + "!")
• Build a mini chatbot:
name = input("What's your name? ")
favorite_color = input("What's your favorite color? ")
print ("Nice to meet you, " + name + "! " + favorite_color + " is a great color!“)
Your Turn to Build a
“Get to Know Me” chatbot
• Create a “Get to Know Me” chatbot that asks for the user’s:
✓ Name
✓ Favorite food
✓ Hobby
• Print a fun introduction using their answers.
Build a “Guess the Animal” game
• Write a Python program to store facts about an animal using well-named variables. The
program will give clues to the user and let them guess the animal.
• Create variables to store the following facts about an animal:
✓ Name of the animal (but don’t reveal it yet).
✓ Its habitat (e.g., forest, ocean, desert).
✓ Its diet type (herbivore, carnivore, omnivore).
✓ One unique feature (e.g., has a long trunk, can fly, is nocturnal).
• Print the clues in a fun way to give hints to the user.
• At the end, let the user guess the animal based on the clues.
Conditional Statements
• Conditional statements help us make decisions in our program based on specific
conditions.
• Real-Life Example:
✓ If it’s raining, take an umbrella.
✓ Else, enjoy the sunshine!
• In Python, we use if, elif, and else to create these decisions.
Syntax of if, elif, and else
• if: Check a condition.
• elif: Check another condition if the first one is false.
• else: Do something if none of the conditions are true.
weather = "rainy"
if (weather == "sunny“):
print ("Wear sunglasses!")
elif (weather == "rainy“):
print ("Take an umbrella!")
else:
print ("Check the weather forecast.")
Relational Operators
• Relational operators are used to compare values:
> (greater than)
< (less than)
== (equal to)
!= (not equal to)
>= (greater than or equal to)
<= (less than or equal to)
Logical Operators
• Logical operators combine multiple conditions:
and: All conditions must be true.
or: At least one condition must be true.
not: Reverses the result.
Hands-On Practice:
Positive, Negative, or Zero
number = int(input("Enter a number: "))
if (number > 0):
print ("The number is positive.")
elif (number < 0):
print ("The number is negative.")
else:
print ("The number is zero.")
Movie Ticket Price Program
• Create a program that calculates the price of a movie ticket based on the user’s age:
1. Ask the user to enter their age using the input() function.
2. Use if, elif, and else to define the ticket prices for different age groups:
Age 5 or below: Free ticket.
Age between 6 and 12: Ticket price is $5.
Age between 13 and 60: Ticket price is $10.
Age above 60: Ticket price is $7 (senior discount).
3. Use print() to display the ticket price for the user based on their age.
Pizza Order Helper
• Create a Python program that helps the user decide the size of a pizza based on how
hungry they are:
1. Ask the user how hungry they are using the input() function.
Provide three options for hunger level: "not much“, "somewhat“, "very“
2. Use if, elif, and else to suggest a pizza size based on the user’s input:
If hunger level is "not much": Recommend a small pizza.
If hunger level is "somewhat": Recommend a medium pizza.
If hunger level is "very": Recommend a large pizza.
3. Use print() to display the suggested pizza size.
“Computers are incredibly fast, accurate, and stupid.
Human beings are incredibly slow, inaccurate, and
brilliant. Together they are powerful beyond imagination.”
- Albert Einstein