Learn how to print messages in Python.
print("Hello, World!")
Explore basic math operations.
print(5 + 3) print(10 - 4) print(2 * 6) print(15 / 3)
Store numbers or text in variables.
name = "Alex" age = 10 print(name) print(age)
Work with text in Python.
greeting = "Hi, friends!" print(greeting) print("I am " + "awesome!")
Ask the user for information.
name = input("What’s your name? ") print("Hello, " + name + "!")
Make a basic calculator.
num1 = 5 num2 = 3 print("Sum:", num1 + num2)
Learn to compare values.
a = 10 b = 5 print(a > b) print(a == b)
Make simple decisions.
age = 8 if age < 10: print("You’re young!")
Add an alternative choice.
age = 12 if age < 10: print("Young!") else: print("Older!")
Ask for a favorite color.
color = input("What’s your favorite color? ") print("Cool! I like " + color + " too!")
Use a loop to count.
for i in range(5): print(i + 1)
A simple guessing game.
number = 7 guess = int(input("Guess a number (1-10): ")) if guess == number: print("You got it!") else: print("Try again!")
Draw a line with Turtle.
import turtle t = turtle.Turtle() t.forward(100)
Draw a square with Turtle.
import turtle t = turtle.Turtle() for i in range(4): t.forward(50) t.right(90)
Generate random numbers.
import random num = random.randint(1, 10) print("Random number:", num)
Create a fun story.
name = input("Enter a name: ") print(name + " went on an adventure!")
Color your Turtle drawings.
import turtle t = turtle.Turtle() t.color("blue") t.forward(100)
Ask a yes/no question.
answer = input("Do you like pizza? (yes/no): ") if answer == "yes": print("Me too!") else: print("Oh, okay!")
Count down from 5.
for i in range(5, 0, -1): print(i) print("Blast off!")
Create a tiny quiz.
answer = input("What is 2 + 2? ") if answer == "4": print("Correct!") else: print("Try again!")
Repeat actions with a for loop.
for i in range(5): print("Looping:", i)
Loop until a condition changes.
count = 0 while count < 5: print(count) count += 1
Store multiple items in a list.
animals = ["cat", "dog", "bird"] print(animals[1])
Add items to a list.
fruits = ["apple", "banana"] fruits.append("orange") print(fruits)
Print every item in a list.
colors = ["red", "blue", "green"] for color in colors: print(color)
Pick a random item.
import random foods = ["pizza", "burger", "ice cream"] print(random.choice(foods))
Use ifs inside ifs.
age = 12 if age > 10: if age < 15: print("You’re a pre-teen!")
Add more conditions.
score = 85 if score >= 90: print("A") elif score >= 80: print("B") else: print("C")
Guess until correct.
import random number = random.randint(1, 10) guess = 0 while guess != number: guess = int(input("Guess (1-10): ")) print("You got it!")
Draw a star.
import turtle t = turtle.Turtle() for i in range(5): t.forward(100) t.right(144)
Find how many items are in a list.
toys = ["ball", "doll", "car"] print(len(toys))
Remove an item from a list.
items = ["pen", "book", "ruler"] items.remove("book") print(items)
Print a times table.
num = 5 for i in range(1, 11): print(num, "x", i, "=", num * i)
Draw a colorful square.
import turtle t = turtle.Turtle() colors = ["red", "blue", "green", "yellow"] for i in range(4): t.color(colors[i]) t.forward(50) t.right(90)
Build a story with inputs.
name = input("Enter a name: ") place = input("Enter a place: ") print(name + " went to " + place + "!")
Check if a number is even or odd.
num = int(input("Enter a number: ")) if num % 2 == 0: print("Even!") else: print("Odd!")
Draw a circle with Turtle.
import turtle t = turtle.Turtle() t.circle(50)
Track scores in a list.
scores = [] for i in range(3): score = int(input("Enter score: ")) scores.append(score) print("Scores:", scores)
Create a pattern with loops.
for i in range(1, 6): print("*" * i)
A multi-question quiz.
score = 0 answer = input("What’s 3 + 5? ") if answer == "8": score += 1 answer = input("What’s 10 - 2? ") if answer == "8": score += 1 print("Score:", score)
Create reusable code.
def greet(name): print("Hello, " + name + "!") greet("Alice")
Store key-value pairs.
scores = {"Alice": 95, "Bob": 88} print(scores["Alice"])
Add new entries.
ages = {"Tom": 10} ages["Sara"] = 12 print(ages)
Get values from functions.
def add(a, b): return a + b result = add(3, 4) print(result)
Combine lists and dictionaries.
students = [{"name": "Lily", "age": 11}, {"name": "Max", "age": 13}] print(students[0]["name"])
Loops inside loops.
for i in range(3): for j in range(2): print(i, j)
Save text to a file.
with open("story.txt", "w") as file: file.write("Once upon a time...")
Read text from a file.
with open("story.txt", "r") as file: print(file.read())
Move Turtle in a loop.
import turtle t = turtle.Turtle() for i in range(36): t.forward(10) t.right(10)
Create a calculator.
def calc(num1, num2, op): if op == "+": return num1 + num2 elif op == "-": return num1 - num2 print(calc(5, 3, "+"))
Create a simple class.
class Pet: def __init__(self, name): self.name = name dog = Pet("Rex") print(dog.name)
Add actions to a class.
class Cat: def __init__(self, name): self.name = name def meow(self): print(self.name + " says meow!") cat = Cat("Luna") cat.meow()
Create lists faster.
numbers = [x * 2 for x in range(5)] print(numbers)
Handle mistakes gracefully.
try: num = int(input("Enter a number: ")) except: print("That’s not a number!")
Make a random story.
import random names = ["Zoe", "Eli"] places = ["park", "zoo"] print(random.choice(names) + " went to the " + random.choice(places))
Move Turtle with keys.
import turtle t = turtle.Turtle() screen = turtle.Screen() screen.listen() screen.onkey(lambda: t.forward(10), "Up") screen.mainloop()
Sort items in a list.
numbers = [5, 2, 8, 1] numbers.sort() print(numbers)
Create a random password.
import random chars = "abc123" password = "".join(random.choice(chars) for _ in range(6)) print(password)
Show the time.
import time for i in range(5): print(time.ctime()) time.sleep(1)
Build a text adventure.
def start(): choice = input("Left or right? ") if choice == "left": print("You found treasure!") else: print("You fell in a hole!") start()