Practice and reinforce the concepts from Lesson 3
Time needed: 30-40 minutes
What you'll do: Become a math wizard with Python! You'll create three cool programs that calculate ages, keep score in games, and perform amazing mathematical operations. Get ready to make Python do the math for you! :emoji::sparkles:
:white_check_mark: You've completed the Operators lesson
:white_check_mark: You understand basic math operations (+, -, *, /)
:white_check_mark: You know how to create variables in Python
:white_check_mark: You're ready to make Python calculate things
:white_check_mark: Remember: Computers are amazing at math!
Go to: https://app.edublocks.org/login and sign in with your Google account
:bulb: :emoji: Save Smart: Hit save every 5 minutes! Your future self will thank you!
Your Three Coding Challenges! :dart:
Exercise One: Age Calculator :emoji:
Your Mission: Create a program that calculates how old someone is!
Step-by-Step Instructions:
- Drag the input block (found in Basic -> Input)
- Type the question: "What year were you born?"
- Store the answer in a variable called
year_born
- Don't forget to convert it to an integer using the int() block!
- Create a variable for current year
- Drag a variable block from Variables
- Name it
year
and set it to 2024 (or the current year)- Time for math magic! :sparkles:
- Drag a new variable block called
age
- Use the subtraction operator block (-)
- Connect:
age = year - year_born
- This calculates the person's age!
- Display the result
- Drag a print block
- Use the join block to combine: "Your age is " + str(age)
- Remember to convert age to a string first!
tip :dart: Test it out: Try different birth years to see if your calculator works correctly!
Common mistake: Forgot to convert to integer? Your program might crash! Always use the int() block when working with numbers from input.
Your Mission: Build a game score tracker that adds points!
Step-by-Step Instructions:
Create your starting score
score
and set value to 100
First power-up! (+300 points) :dart:
score += 300
(this adds 300 to score)Second power-up! (+300 more points) :dart:
score += 300
againWhat you'll see:
:bulb: :video_game: Game Developer Tip: The += operator is a shortcut! Instead of writing
score = score + 300
, you can just writescore += 300
. Cool, right?Python Connection: In real Python code, game developers use += all the time to update player scores, health points, and inventory items!
Your Mission: Create a calculator that shows different math operations!
Step-by-Step Instructions:
Set up your numbers :emoji:
num1
and set to 10
num2
and set to 5
Show your chosen numbers
Perform the calculations! :emoji:
Example output:
Let num1 = 10
Let num2 = 5
Your num1: 10
Your num2: 5
Subtraction result: 5
Addition result: 15
Division result: 2.0
:bulb: :emoji: Math Lab Bonus: Try adding multiplication (num1 * num2) and see what happens! You can even try with negative numbers or decimals!
Troubleshooting: If you see "2.0" instead of "2" for division, that's normal! Python shows division results as decimals (floats) to be precise.
Finished early? Try these extras:
months = age * 12
days = age * 365
Complete all three exercises and show off your operator skills!
Submit Your Python Operators Projects Here!
Remember: You need to submit 3 project links - one for each exercise!
:bulb: :memo: Submission Tip: Name your projects clearly so you don't mix them up:
- "YourName_AgeCalculator"
- "YourName_ScoreKeeper"
- "YourName_MathLab"
Congratulations! You've learned how to:
Keep practicing with operators - they're the building blocks of every program you'll create! :rocket: