This page will serve as a go to page for lesson, activites and code
Get in TouchEach code snippet has syntax problem.
In programming, syntax means the set of rules that define how code must be written and structured so that a computer can understand it.
Think of it as the grammar and spelling of a programming language.
Just like English has grammar (e.g., subject + verb + object), programming languages have syntax rules (e.g., where parentheses, colons, or keywords must go).
if x = 5:
print(x)
if True:
print("This is ddafdasfd")
print("This is fafasfdas")
age = 18
if age = 18:
print("You are an adult.")
#Trying to add 2 integers
x = 5
y = input("Please Enter a number: ")
print(x + y)
x = 5
if x > 10:
print("Big number!")
else
print("Small number!")
for i in range(5)
print(i)
numbers = [1, 2, 3, 4]
for num in numbers:
print(num * 2)
count = 0
while count < 5
print(count)
count += 1
count = 0
while count < 3:
print("Count is:", count)
#2 Errors 1variable = 10 my variable = 20
print(name) name = "Alice"
num1 = 10 num2 = "20" result = num1 + Num2 print(result) #Has 2 errors
name = "Harry" print(naMe)
print(Hello World)
print "Hello World"
msg = "Hello World print(msg)
another_message = 'Python is fun!"
message = 'Hello World!" print(message)
word = "Python" print(word[6])
numbers = [1 2, 3]
my_list = [1, 2, 3
my_list = [1, 2, 3}
fruits = ["apple", "banana", "cherry"] print(fruits[3])
numbers = [1, 2, 3] numbers.add([4, 5, 6]) print(numbers)
In programming, a logical error is a type of bug that happens when your code runs without crashing, but it doesn’t do what you intended — because there’s a mistake in the logic or reasoning behind the code.
#Goal determine who is a teenager and who is an adult
age = 15
if age > 18:
print("You are a teenager.")
else:
print("You are an adult.")
#Goal is print average of 2 numbers a = 10 b = 20 avg = a + b / 2 print(avg)
# Goal: print numbers greater than 3
numbers = [1, 2, 3, 4, 5]
for n in numbers:
if n > 3:
pass
print(n)
# Goal: print numbers 1 to 5
total = 0
for i in range(1, 5):
total += i
print("Sum from 1 to 5 is:", total)
#Goal is print a countdown from 5 to 0
count = 5
while count == 0:
print(count)
count -= 1
#Goal find total of numbers between 0 and 4
total = 0
for i in range(5):
total = i # ❌ overwrites total every time
print(total)
#Goal find the longest word in a list of words
words = ["apple", "banana", "cherry"]
longest = ""
for word in words:
if len(word) < len(longest):
longest = word
print("Longest word is:", longest)
#Goal print if x is between 0 and 10
if x > 0 or x < 10: # Logical error: always true
print("x is between 0 and 10")
i = 0
while i < 5:
print(i)
A while loop repeatedly executes a block of code as long as a condition is True.
It’s useful when you don’t know exactly how many times you need to loop — for example, waiting for user input, or looping until a certain calculation is complete.
while condition:
# code to repeat
count = 1
while count <= 5:
print("Count is:", count)
count += 1 # increase count by 1 each time
If your condition never becomes False, the loop runs forever.
while True:
print("This will never stop!") # use Ctrl+C to stop manually
To avoid this, make sure something inside the loop changes so the condition will eventually fail.
password = ""
while password != "open sesame":
password = input("Enter the password: ")
print("Access granted!")
The loop keeps asking until the user types "open sesame".
Once the condition is false (password != "open sesame" becomes false), it exits.
You can exit a loop early using break.
while True:
num = int(input("Enter a number (0 to quit): "))
if num == 0:
break
print("You entered:", num)
When the user types 0, the break statement immediately ends the loop.
You can skip the rest of a loop iteration using continue.
n = 0
while n < 10:
n += 1
if n % 2 == 0:
continue # skip even numbers
print(n)
This prints only the odd numbers between 1 and 9.
A for loop lets you repeat an action for each item in a sequence (like a list, range, or string).
When you use it with a string, it goes through each character one by one.
for variable in sequence:
# code to run for each item
for letter in "hello":
print(letter)
print("Hello")
print("World")
print(value, end="something")
print("Hello", end=" ")
print("World")
for i in range(5):
print(i, end=", ")
for letter in "ABC":
print(letter, end="")
import random
def select (simple_words):
return random.choice(simple_words)
simple_words = ["apple", "basic", "cloud", "dance", "flute",
"fruit", "grape", "image", "knife", "lemon", "mouse", "paste",
"queen", "ratio", "scene", "space", "taste", "unite", "virus",
"water", "bread", "chair", "diner", "ember", "fence", "games",
"heart", "image", "judge", "knead", "laugh", "mouse", "nurse", "ocean", "paste", "queen", "ratio", "scene", "sense", "space", "speed", "spell", "sport", "steam", "style", "table", "taste", "timer", "touch", "tower", "train", "trust", "truth", "usage", "vault", "verse", "watch", "water", "waves", "whale", "wheel", "where", "which", "while", "white", "whole", "whose", "woman", "women", "world", "worth", "would", "write", "wrong", "year", "yield", "youth", "zest", "zips", "zones", "alive", "angel", "blood", "board", "brain", "cards", "carry", "cells", "chart", "chief", "class", "clone", "clubs", "coach", "craft", "crave", "crazy", "cross", "crowd", "crush", "dance"]
wrong_guesses =0
max_wrong_guesses =6
#print(simple_words[53])
random_item = select(simple_words)
wordset = set(random_item)
print(wordset)
print(random_item)
list = " _ " * len(random_item)
list = list.split()
print(list)
while wrong_guesses < max_wrong_guesses:
#i+= 1
if wrong_guesses == 3:
continue
#print(i)
guess=input('guess letter:')
if guess in random_item:
print("Guess correct")
else:
print("Guess incorrect")
import random
def selectword():
return random.choice(simple_words)
simple_words = [
"apple", "bread", "chair", "dance", "eagle", "floor", "grape", "house", "ivory", "juice",
"knife", "lemon", "money", "nurse", "ocean", "pizza", "queen", "river", "spoon", "table",
"umbra", "voice", "water", "zebra", "angel", "block", "cloud", "drink", "earth", "fruit",
"grass", "happy", "inbox", "jelly", "kitty", "laugh", "mango", "night", "onion", "plant",
"quiet", "roast", "shell", "train", "unity", "vivid", "whale", "xyloh", "young", "zebra",
"smile", "brush", "clock", "dream", "fairy", "ghost", "horse", "inlet", "jolly", "kneel",
"light", "magic", "novel", "olive", "peach", "quilt", "razor", "scoop", "teach", "uncle",
"visit", "watch", "yearn", "zebra", "alert", "bacon", "color", "dance", "enter", "frost",
"glove", "honey", "ideal", "joint", "knock", "limit", "music", "never", "outer", "prime",
"quiet", "round", "sleep", "tasty", "under", "voter", "world", "xerox", "yield", "zooms"
]
guesses=set()
correctguesses=set()
list = [1, 4, 5, 2, 7, 9, 12, 3]
random_element = selectword()
wordlist=set(random_element)
print(wordlist)
print(f"The randomly chosen element is: {random_element}")
guesses=4
guess = input("guess a letter")
if guess not in guesses :
if guess in random_element:
print("guess correctly")
else:
print("guess incorrectly")
import random
def selectword():
return random.choice(simple_words)
def printdashes():
for character in random_element:
if character in correctguesses:
print ("character",end= " ")
else:
print("-",end=" ")
print()
simple_words = [
"apple", "bread", "chair", "dance", "eagle", "floor", "grape", "house", "ivory", "juice",
"knife", "lemon", "money", "nurse", "ocean", "pizza", "queen", "river", "spoon", "table",
"umbra", "voice", "water", "zebra", "angel", "block", "cloud", "drink", "earth", "fruit",
"grass", "happy", "inbox", "jelly", "kitty", "laugh", "mango", "night", "onion", "plant",
"quiet", "roast", "shell", "train", "unity", "vivid", "whale", "xyloh", "young", "zebra",
"smile", "brush", "clock", "dream", "fairy", "ghost", "horse", "inlet", "jolly", "kneel",
"light", "magic", "novel", "olive", "peach", "quilt", "razor", "scoop", "teach", "uncle",
"visit", "watch", "yearn", "zebra", "alert", "bacon", "color", "dance", "enter", "frost",
"glove", "honey", "ideal", "joint", "knock", "limit", "music", "never", "outer", "prime",
"quiet", "round", "sleep", "tasty", "under", "voter", "world", "xerox", "yield", "zooms"
]
guesses=set()
correctguesses=set()
#list = [1, 4, 5, 2, 7, 9, 12, 3]
random_element = selectword()
printdashes()
wordset =set(random_element)
#print(wordset)
guesses = 5
incorrectguesses =0
print (random_element)
while guesses -incorrectguesses >0:
guess = input("guess the letter ")
#guesses.add
if guess not in guesses:
if guess in random_element:
guesses.add(guess)
correctguesses.add(guess)
print("guess correctly")
else:
print("guess incorrectly")
incorrectguesses+=1
else:
print("You guessed this letter already")
def selectword():
return random.choice(four_letter_words)
def printdashes():
for character in random_element:
if character in correctguesses:
print(character, end=" ")
else:
print(end="-")
print()
four_letter_words = [
"Ball",
"Bark",
"Base",
"Bath",
"Bear",
"Bell",
"Belt",
"Bend",
"Best",
"Bird",
"Book",
"Boot",
"Cake",
"Call",
"Camp",
"Card",
"Cart",
"Chat",
"Chip",
"Clap",
"Clip",
"Club",
"Cold",
"Cook",
"Cool",
"Corn",
"Crab",
"Dark",
"Dash",
"Desk",
"Dive",
"Doll",
"Door",
"Down",
"Draw",
"Drop",
"Duck",
"Dust",
"Earn",
"Edge",
"Face",
"Fall",
"Farm",
"Fast",
"Feed",
"Find",
"Fire",
"Fish",
"Flat",
"Flip",
"Fold",
"Food",
"Foot",
"Fork",
"Frog",
"Full",
"Game",
"Gift",
"Girl",
"Good",
"Grab",
"Hand",
"Hard",
"Hate",
"Have",
"Head",
"Hear",
"Help",
"Hill",
"Hold",
"Home",
"Hope",
"Jump",
"Kick",
"King",
"Lamp",
"Land",
"Left",
"Life",
"Lift",
"Line",
"Lion",
"Lock",
"Look",
"Love",
"Make",
"Mark",
"Meal",
"Meet",
"Milk",
"Move",
"Neck",
"Open",
"Park",
"Play",
"Read",
"Ride",
"Ring",
"Road",
"Rock",
]
guesses = set()
correctguesses = set()
random_element = selectword().lower()
word_set = set(random_element)
print(word_set)
printdashes()
print(f"The randomly chosen word is : {random_element}")
guesslimit = 4
incorrectguesses = 0
print (random_element)
while (guesslimit-incorrectguesses)>0 and len(correctguesses) != len(word_set):
guess = input("Guess a letter")
if guess not in guesses:
if guess in random_element:
guesses.add(guess)
print("guess correctly")
correctguesses.add(guess)
printdashes()
else:
guesses.add(guess)
print("guess incorrectly")
incorrectguesses+=1
print (f"you have {guesslimit-incorrectguesses} left")
if len(correctguesses) == len(word_set):
print(f"Congratulations!!! You have guessed the word correctly")
else:
print(f"I'm sorry!You've lost")
import random
def select (simple_words):
return random.choice(simple_words)
simple_words = ["apple", "basic", "cloud", "dance", "flute", "fruit", "grape", "image", "knife", "lemon", "mouse", "paste", "queen", "ratio", "scene", "space", "taste", "unite", "virus", "water", "bread", "chair", "diner", "ember", "fence", "games", "heart", "image", "judge", "knead", "laugh", "mouse", "nurse", "ocean", "paste", "queen", "ratio", "scene", "sense", "space", "speed", "spell", "sport", "steam", "style", "table", "taste", "timer", "touch", "tower", "train", "trust", "truth", "usage", "vault", "verse", "watch", "water", "waves", "whale", "wheel", "where", "which", "while", "white", "whole", "whose", "woman", "women", "world", "worth", "would", "write", "wrong", "year", "yield", "youth", "zest", "zips", "zones", "alive", "angel", "blood", "board", "brain", "cards", "carry", "cells", "chart", "chief", "class", "clone", "clubs", "coach", "craft", "crave", "crazy", "cross", "crowd", "crush", "dance"]
wrong_guesses =0
max_wrong_guesses =6
#print(simple_words[53])
random_item = select(simple_words)
print(random_item)
list = " _ " * len(random_item)
list = list.split()
print(list)
wrong_guesses
while wrong_guesses < max_wrong_guesses:
i+= 1
if wrong_guesses == 3:
continue
print(i)
guess=input('guess letter:')
if guess in random_item:
print("Guess correct")
else:
print("Guess incorrect")
import random
def selectword():
return random.choice(four_letter_words)
four_letter_words = [
"Ball", "Bark", "Base", "Bath", "Bear", "Bell", "Belt", "Bend", "Best", "Bird",
"Book", "Boot", "Cake", "Call", "Camp", "Card", "Cart", "Chat", "Chip", "Clap",
"Clip", "Club", "Cold", "Cook", "Cool", "Corn", "Crab", "Dark", "Dash", "Desk",
"Dive", "Doll", "Door", "Down", "Draw", "Drop", "Duck", "Dust", "Earn", "Edge",
"Face", "Fall", "Farm", "Fast", "Feed", "Find", "Fire", "Fish", "Flat", "Flip",
"Fold", "Food", "Foot", "Fork", "Frog", "Full", "Game", "Gift", "Girl", "Good",
"Grab", "Hand", "Hard", "Hate", "Have", "Head", "Hear", "Help", "Hill", "Hold",
"Home", "Hope", "Jump", "Kick", "King", "Lamp", "Land", "Left", "Life", "Lift",
"Line", "Lion", "Lock", "Look", "Love", "Make", "Mark", "Meal", "Meet", "Milk",
"Move", "Neck", "Open", "Park", "Play", "Read", "Ride", "Ring", "Road", "Rock"
]
random_element=selectword()
print(selectword())
print(f"The randomly chosen word is : {random_element}")
guess = 5
input("guess a letter that might be in the word")
print(input)
if guese is random_element:
print ("guess correctly")
else:
print(guss incorrectly)
A set is an unordered, mutable, and unique collection of elements.
# Using curly braces
fruits = {"apple", "banana", "cherry"}
print(fruits)
# Using the set() constructor
numbers = set([1, 2, 3, 4])
print(numbers)
# Empty set (must use set(), not {})
empty = set()
print(type(empty)) #
colors = {"red", "green"}
colors.add("blue")
print(colors) # {'red', 'green', 'blue'}
colors.update(["yellow", "orange"]) print(colors)
fruits = {"apple", "banana", "cherry"}
fruits.remove("banana") # Removes an item (raises error if not found)
print(fruits)
fruits.discard("mango") # Removes safely (no error if missing)
print(fruits)
fruits.pop() # Removes a random element
print(fruits)
fruits.clear() # Empties the set
print(fruits)
fruits = {"apple", "banana", "cherry"}
print("banana" in fruits) # True
print("orange" not in fruits) # True
In programming, a function is a reusable block of code designed to perform a specific task. Instead of writing the same code multiple times, you can define a function once and call it whenever needed.
In video games, functions are widely used for actions like attacking, healing, jumping, or calculating scores.
To define a function in Python, use the def keyword followed by the function name and parentheses. If the function has parameters (inputs), you put them inside the parentheses.
def greet():
print("Hello, welcome to Python!")
Once a function is defined, you can call (invoke) it by using its name followed by parentheses.
greet()
You can pass information to a function using parameters. Parameters are specified inside the parentheses in the function definition.
def greet(name):
print(f"Hello, {name}!")
Calling the Function
greet("Alice") # Calling the function with the argument "Alice"
greet("Bob") # Calling the function with the argument "Bob"
A function can take multiple parameters. Just separate them with commas inside the parentheses.
def add(a, b):
result = a + b
print(f"The sum of {a} and {b} is {result}")
Calling function
add(5, 3)
You can give parameters default values, which are used if no argument is provided when the function is called.
def greet(name="Guest"):
print(f"Hello, {name}!")
You can call with arguments or without arguments
greet("Alice") # Hello, Alice!
greet() # Hello, Guest!
stages = [
'''
-----
| |
O |
/|\\ |
/ \\ |
|
=========
''',
'''
-----
| |
O |
/|\\ |
/ |
|
=========
''',
'''
-----
| |
O |
/|\\ |
|
|
=========
''',
'''
-----
| |
O |
/| |
|
|
=========
''',
'''
-----
| |
O |
| |
|
|
=========
''',
'''
-----
| |
O |
|
|
|
=========
''',
'''
-----
| |
|
|
|
|
=========
'''
]
import random
def selectword():
return random.choice(four_letter_words)
four_letter_words = [
"Ball", "Bark", "Base", "Bath", "Bear", "Bell", "Belt", "Bend", "Best", "Bird",
"Book", "Boot", "Cake", "Call", "Camp", "Card", "Cart", "Chat", "Chip", "Clap",
"Clip", "Club", "Cold", "Cook", "Cool", "Corn", "Crab", "Dark", "Dash", "Desk",
"Dive", "Doll", "Door", "Down", "Draw", "Drop", "Duck", "Dust", "Earn", "Edge",
"Face", "Fall", "Farm", "Fast", "Feed", "Find", "Fire", "Fish", "Flat", "Flip",
"Fold", "Food", "Foot", "Fork", "Frog", "Full", "Game", "Gift", "Girl", "Good",
"Grab", "Hand", "Hard", "Hate", "Have", "Head", "Hear", "Help", "Hill", "Hold",
"Home", "Hope", "Jump", "Kick", "King", "Lamp", "Land", "Left", "Life", "Lift",
"Line", "Lion", "Lock", "Look", "Love", "Make", "Mark", "Meal", "Meet", "Milk",
"Move", "Neck", "Open", "Park", "Play", "Read", "Ride", "Ring", "Road", "Rock"
]
random_element=selectword()
print(selectword())
print(f"The randomly chosen word is : {random_element}")
guess = 5
input("guess a letter that might be in the word")
print(input)
if guese is random_element:
print ("guess correctly")
else:
print(guss incorrectly)
import random
def selectword():
return random.choice(simple_words)
def printdashes():
for character in random_element:
if character in correctguesses:
print("character",end=" ")
else:
print(end="-")
print()
simple_words = [
"apple", "bread", "chair", "dance", "eagle", "floor", "grape", "house", "ivory", "juice",
"knife", "lemon", "money", "nurse", "ocean", "pizza", "queen", "river", "spoon", "table",
"umbra", "voice", "water", "zebra", "angel", "block", "cloud", "drink", "earth", "fruit",
"grass", "happy", "inbox", "jelly", "kitty", "laugh", "mango", "night", "onion", "plant",
"quiet", "roast", "shell", "train", "unity", "vivid", "whale", "xyloh", "young", "zebra",
"smile", "brush", "clock", "dream", "fairy", "ghost", "horse", "inlet", "jolly", "kneel",
"light", "magic", "novel", "olive", "peach", "quilt", "razor", "scoop", "teach", "uncle",
"visit", "watch", "yearn", "zebra", "alert", "bacon", "color", "dance", "enter", "frost",
"glove", "honey", "ideal", "joint", "knock", "limit", "music", "never", "outer", "prime",
"quiet", "round", "sleep", "tasty", "under", "voter", "world", "xerox", "yield", "zooms"
]
guesses=set()
correctguesses=set()
list = [1, 4, 5, 2, 7, 9, 12, 3]
random_element = selectword()
printdashes()
wordlist=set(random_element)
print(wordlist)
print(f"The randomly chosen element is: {random_element}")
guess = input("guess a letter")
guesses=4
incorrectguesses=0
while guesses-incorrectguesses<0:
if guess not in guesses:
if guess in random_element:
print("guess correctly")
else:
print("guess incorrectly")
incorrectguesses+=1
import random
def selectword():
return random.choice(simple_words)
simple_words = [
"apple", "bread", "chair", "dance", "eagle", "floor", "grape", "house", "ivory", "juice",
"knife", "lemon", "money", "nurse", "ocean", "pizza", "queen", "river", "spoon", "table",
"umbra", "voice", "water", "zebra", "angel", "block", "cloud", "drink", "earth", "fruit",
"grass", "happy", "inbox", "jelly", "kitty", "laugh", "mango", "night", "onion", "plant",
"quiet", "roast", "shell", "train", "unity", "vivid", "whale", "xyloh", "young", "zebra",
"smile", "brush", "clock", "dream", "fairy", "ghost", "horse", "inlet", "jolly", "kneel",
"light", "magic", "novel", "olive", "peach", "quilt", "razor", "scoop", "teach", "uncle",
"visit", "watch", "yearn", "zebra", "alert", "bacon", "color", "dance", "enter", "frost",
"glove", "honey", "ideal", "joint", "knock", "limit", "music", "never", "outer", "prime",
"quiet", "round", "sleep", "tasty", "under", "voter", "world", "xerox", "yield", "zooms"
]
list = [1, 4, 5, 2, 7, 9, 12, 3]
random_element = selectword()
guesses = 5
print (random_element)
guess = input("guess the letter ")
if guess in random_element:
print("guess correctly")
else:
print("guess incorrectly")
#print(selectword())
#print(selectword())
import random
def selectword ():
return random.choice(four_letter_words)
four_letter_words = [
"Ball", "Bark", "Base", "Bath", "Bear", "Bell", "Belt", "Bend", "Best", "Bird",
"Book", "Boot", "Cake", "Call", "Camp", "Card", "Cart", "Chat", "Chip", "Clap",
"Clip", "Club", "Cold", "Cook", "Cool", "Corn", "Crab", "Dark", "Dash", "Desk",
"Dive", "Doll", "Door", "Down", "Draw", "Drop", "Duck", "Dust", "Earn", "Edge",
"Face", "Fall", "Farm", "Fast", "Feed", "Find", "Fire", "Fish", "Flat", "Flip",
"Fold", "Food", "Foot", "Fork", "Frog", "Full", "Game", "Gift", "Girl", "Good",
"Grab", "Hand", "Hard", "Hate", "Have", "Head", "Hear", "Help", "Hill", "Hold",
"Home", "Hope", "Jump", "Kick", "King", "Lamp", "Land", "Left", "Life", "Lift",
"Line", "Lion", "Lock", "Look", "Love", "Make", "Mark", "Meal", "Meet", "Milk",
"Move", "Neck", "Open", "Park", "Play", "Read", "Ride", "Ring", "Road", "Rock"
]
random_element =selectword().lower()
#print( selectword ())
print(f"The randomly chosen word is : {random_element}")
guesse = 10
#print (random_element)
guesse=input("Guesse a letter that might be in the word ")
if guesse in random_element:
print("guesse correctly")
else:
print("guesse incorrectly")
import random
def select (simple_words):
return random.choice(simple_words)
print(f"simple_words")
simple_words = ["apple", "basic", "cloud", "dance", "flute", "fruit", "grape", "image", "knife", "lemon", "mouse", "paste", "queen", "ratio", "scene", "space", "taste", "unite", "virus", "water", "bread", "chair", "diner", "ember", "fence", "games", "heart", "image", "judge", "knead", "laugh", "mouse", "nurse", "ocean", "paste", "queen", "ratio", "scene", "sense", "space", "speed", "spell", "sport", "steam", "style", "table", "taste", "timer", "touch", "tower", "train", "trust", "truth", "usage", "vault", "verse", "watch", "water", "waves", "whale", "wheel", "where", "which", "while", "white", "whole", "whose", "woman", "women", "world", "worth", "would", "write", "wrong", "year", "yield", "youth", "zest", "zips", "zones", "alive", "angel", "blood", "board", "brain", "cards", "carry", "cells", "chart", "chief", "class", "clone", "clubs", "coach", "craft", "crave", "crazy", "cross", "crowd", "crush", "dance"]
wrong_guesses =0
max_wrong_guesses =6
#print(simple_words[53])
random_item = select(simple_words)
print(random_item)
list = " _ " * len(random_item)
list = list.split()
print(list)
while wrong_guesses < max_wrong_guesses:
i+= 1
if wrong_guesses == 3:
continue
print(i)
guess=input('guess letter:')
if guess in random_item:
print("Guess correct")
else:
print("Guess incorrect")