Say hello
Change the code so it prints your name on one line and your favorite food on the next.
Use two print() lines, one for each thing. Keep the quotes!
Output
Week 1
Make the computer show output with print(), and ask the user questions with input().
print("Hello, world!")
Shows: Hello, world! Each print() shows up on its own line.
"pizza" "I love coding!" "( ^_^ )"
Quotes always come in pairs: one to start, one to end.
name = input("What is your name? ") print("Hi " + name)
The program waits for the user to type and press Enter. Leave a space at the end of your question.
print("My name is " + "Maya")
Shows: My name is Maya. Forget the space and you get “My name isMaya”.
Print("hi")NameError. Use a lowercase p.
print("hi)SyntaxError. Close the quote.
print("hi"SyntaxError. Close the parenthesis.
print(hi)NameError. Text needs quotes.
Edit the code, press Run, and check the output.
Change the code so it prints your name on one line and your favorite food on the next.
Use two print() lines, one for each thing. Keep the quotes!
Output
This code has two bugs. Run it, read the error, and fix it until it works.
Look at the first letter, and count the quotation marks.
Output
Add at least two more questions, and make the program reply to each answer.
Copy the two lines and change the question, like game = input("Favorite game? ").
Output
Week 2
A variable stores a value so your program can remember it and use it later.
name = "Maya" print(name)
Variable name on the left, value on the right. Read = as “stores”.
name = "Maya" print(name) # Maya print("name") # name
No quotes: use what’s in the box. Quotes: print the exact text.
food = "pizza" food = "tacos" print(food) # tacos
A variable holds one value at a time: the newest one.
my_nameName and name are differentmy name = "Ava"SyntaxError. No spaces in names: my_name.
name = MayaNameError. The value needs quotes.
print(Name)NameError. Capitals must match exactly.
Edit the code, press Run, and check the output.
Before you press Run, type what you think this code will print.
How many values can one box hold at a time?
Output
Make variables for your favorite food and game, print them, then change a value and run it again.
Only change the part inside the quotes on the right of the = sign.
Output
Ask for more words and write your own silly story with at least three print() lines.
Try asking for a place, a number, or an action word. Watch the spaces inside your quotes.
Output
Week 3
Every value has a type. The type decides what you can do with it, like math or joining text.
"hello" "42"
Text in quotes, even if it looks like a number.
12 500 -3
A whole number. No quotes.
3.5 9.99
A number with a decimal point.
print(5 + 3) # 8 add print(9 - 4) # 5 subtract print(6 * 7) # 42 multiply print(7 / 2) # 3.5 divide
Multiply is a star *, not an x.
print("5" + "5") # 55 print(5 + 5) # 10
Strings get glued together. Integers get added.
age = int(input("Age? ")) print(age + 1)
int() turns the typed text into a number so you can do math.
print("You are " + str(age))
str() turns a number back into text so + can join it to a sentence.
print("Age: " + 12)TypeError. Use str(12) to join a number.
int("twelve")ValueError. int() needs digits like 12.
int(input("Age? ")SyntaxError. Two ( need two ) at the end.
Edit the code, press Run, and check the output.
How many seconds are in one day? Then add a line that works out how many are in a week.
A week has 7 days. Multiply one more time!
Output
Run this and read the error. Then use int() to fix it so it prints your age next year.
Wrap the whole input(...) inside int( ). Count your parentheses!
Output
Run it, then add your own facts, like your age in months or in 50 years.
Do the math first, like age * 12, then wrap it in str() to add it to your sentence.
Output
Week 4
Teach your program to make decisions. First, meet booleans: values that can only be True or False.
is_raining = True has_homework = False
A new data type with only two values. No quotes, and always a capital T or F.
print(5 > 3) # True print(10 == 2) # False print("cat" == "cat") # True
Python checks the comparison and answers True or False.
== equal to
!= not equal to
> greater than
< less than
>= greater or equal
<= less or equal
= stores a value. == asks “are these equal?”
answer = input("Like pizza? ") if answer == "yes": print("Same!")
If the condition is True, the indented code runs. If it’s False, Python skips it.
if answer == "yes": print("Same!") else: print("More for me!")
else runs when the if is False. One of the two always runs.
if score >= 90: print("Amazing!") elif score >= 70: print("Nice job!") else: print("Keep practicing!")
Python checks from top to bottom and runs only the first one that’s True.
if age = 12:SyntaxError. Use == to compare.
if answer == "yes"SyntaxError. Add a colon at the end.
print("Same!")IndentationError when not indented under the if.
is_fun = trueNameError. Booleans need a capital: True.
if input("Age? ") > 12:TypeError. Use int() before comparing numbers.
"Yes" == "yes"Sneaky bug: this is False. Capitals matter!
Edit the code, press Run, and check the output.
Predict each line before you run it. Then write two comparisons of your own.
!= means “not equal.” Is 10 not equal to 10?
Output
Run it twice: once with the right password and once with a wrong one. Then change the password and the messages.
The password has to match exactly, including capitals. Keep the colons and the indents.
Output
Try different temperatures. Then add another elif for snow weather, like below 32.
Order matters! Put your new check before the else, and think about which check Python reaches first.
Output
Free code
Try anything you want. Write your code, press Run, and see what happens.
Output
Your code is saved on this computer while you work. Use Download to keep a copy or move it to another computer. Tip: press Ctrl + Enter to run.