Python · Conditions
Challenge
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercises
Exercise 1 — Gym Challenge - Badge Check
Before challenging a gym, you need to verify your progress.
Create a program that checks how many badges you have: - If badges < 8: "You're not done yet, next gym to challenge: [badge + 1]" - Elif badges == 8: "Congratulations! You have all badges. Ready for the Elite Three!" - Otherwise: "Invalid badge count." Finally, print: "Good luck, trainer!"
Starter code
badges = 3 # Code here
Exercise 2 — Gym Challenge - Level Requirement
Gyms are grouped by difficulty: - Gyms 1-3 (0-2 badges): Level 10 required - Gyms 4-5 (3-4 badges): Level 20 required - Gyms 6-7 (5-6 badges): Level 30 required - Gym 8 (7 badges): Level 40 required
Create a program that: - Determines the required level based on badges - Compares Zap's level to the requirement - If level >= required: "Zap meets the level requirement!" Otherwise: "Zap needs more training. Required level: [X]"
Starter code
badges = 3 zap_level = 22 # Code here
Exercise 3 — Arena Preparation - Potion Management
You're about to challenge the arena, but first you need to make sure you're well prepared with enough potions! For security reason, the arena ask you to have at least 3 potions to enter safely. Each potion costs 200 coins.
Check if you have enough potions (>= 3) - If yes:
"You're ready!"
- If no: Check if you have enough money to buy more - Calculate how many potions you need and total cost - If you can afford them, increment your potions count, decrement your money, and display:
"Buying X potions for Y coins"
- If you can't afford them, display:
"Not enough money! You need X more coins"
Print your money and number of potions at the end
Starter code
potions = 1 money = 500 potion_price = 200 required_potions = 3 # Code here
Back to the course