Practice and reinforce the concepts from Lesson 2
⏱️ Estimated Time: 45-60 minutes
:dart: What You'll Create: 4 fun programs using variables - including a Mad Libs game and a Banana Generator!
Welcome young coders! Today you'll become a variable wizard! :emoji::emoji:️ You'll learn how to create boxes (variables) to store information, change what's inside them, and even ask users for input. By the end, you'll have created 4 awesome programs!
:bulb: :bulb: Pro Tip: Save your work every 5 minutes! Use Ctrl+S (Windows) or Cmd+S (Mac) for quick saves.
Steps to Complete Your Variables Exercises
One. Exercise (Variables) 1 - My Travel Dreams :emoji:
⏱️ Time: 10 minutes
Goal: Create your first variables and print a message about your travel dreams!Step-by-Step Instructions:
- Drag the
variable =
block from the Variables section- Type
my_country
as the variable name- Set the value to your home country (in quotes for a string!)
- Create another variable called
my_tour_country
- Set it to a country you'd love to visit
- Drag a
print()
block- Build the message: "I'm from my_country and I want to visit my_tour_country"tip :dart: Remember: Text values need quotes around them! Example: "Canada" not just Canada
⏱️ Time: 10 minutes
Goal: Learn how variables can change their values - just like updating a game score!
Step-by-Step Instructions:
variable =
blockscore
and set value to 100
print()
block and print the scorevariable =
block for the SAME variable score
200
300
:bulb: :bulb: Cool Fact: In real Python, variables can change values - that's why they're called "variable" (they vary)! It's like updating your high score in a game.
3. Exercise (Variables Advanced) 1 - Mad Libs Game :emoji:
⏱️ Time: 15 minutes
Goal: Create a hilarious Mad Libs story that asks for user input!What's Mad Libs? It's a word game where you ask for random words, then put them into a story to create something silly and fun!
Step-by-Step Instructions:
- Create Variable "a":
- Drag
variable = input()
block- Name:
a
- Prompt: "Give me an object (plural)!"
- Create Variable "b":
- Drag another
variable = input()
block- Name:
b
- Prompt: "Give me an occupation!"
- Create Variable "c" (with math!):
- Drag
variable = input()
block- Name:
c
- Prompt: "Give me a number which will be multiplied by 1000"
- After this, drag
variable = int()
block to convertc
to a number- Then drag
variable = * 1000
to multiply it!- Create Variables "d", "e", and "f":
- Variable
d
: "Give me a word that describes something!"- Variable
e
: "Give me a word!"- Variable
f
: "Give me a body part!"- Print your complete Mad Libs story using all the variables!tip :rocket: Troubleshooting: If your story doesn't display correctly, check that you're using the variable names (not the values) in your print statement!
⏱️ Time: 10 minutes
Goal: Create a fun program that generates "banana" with customizable length!
How it works: You'll use string multiplication (repeating text) to make bananas of different sizes!
Step-by-Step Instructions:
Create the "na" variable:
variable =
blockna
"na"
(with quotes!)Ask for multiplier:
variable = input()
blockna_multiplier
Convert to number:
variable = int()
blockna_multiplier
to an integerCreate and print the banana:
print()
block"ba" + na * na_multiplier
:warning: Bug Alert: If you see spaces in your banana (like "ba na na na"), make sure you're using the
+
operator to join strings, not commas!Python Fact: In Python, you can multiply strings!
"na" * 3
gives you"nanana"
Before submitting, make sure each exercise has:
Exercise One:
my_country
and my_tour_country
Exercise 2:
score
created with value 100Exercise 3:
Exercise 4:
na
with value "na"Ready for extra challenges? Try these:
Super Variable: Create a program that asks for your name, age, and favorite color, then prints a superhero name based on your inputs!
Calculator Variable: Make a simple calculator that asks for two numbers and shows their sum, difference, and product.
Story Builder: Create an even longer Mad Libs story with 10+ variables!
Pattern Maker: Use string multiplication to create different patterns like triangles or squares with symbols!
When you have completed your "Python Variables Exercises" activity:
:bulb: Tip
:memo: Submission Tip: You need to submit 4 separate project links - one for each exercise. Name them clearly so your teacher knows which is which!
Great job, variable wizards! You've learned one of the most important concepts in programming! :tada: