Challenge
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercisesExercise 1 — Tournament Registration - Name Validation
Welcome to the Codémon Grand Tournament!
The registration system has received a messy Codémon name entry. Your job is to clean it up and validate it.
Create a program that:
- Takes the messy name and removes extra whitespace
- Capitalizes the first letter and makes the rest lowercase (proper name format). Hint: the .capitalize() method will help you!
- Checks if the name length is between 3 and 10 characters (inclusive)
- Prints the cleaned and formatted name
messy_name = " aquaCHU "
# Clean and validate the name hereExercise 2 — Stats Analysis - Power Calculation
The tournament official asks for Aquachu's stats, but they're stored in the system in a compact string format: "ATK:75-DEF:60-SPD:85". (All numbers are 2 digits) You need to extract each stat one by one to report them: - Extract the attack value (the number after 'ATK:') - Extract the defense value (the number after 'DEF:') - Extract the speed value (the number after 'SPD:') - Calculate the average of all three stats - Print all the extracted values and the average
stats = "ATK:75-DEF:60-SPD:85"
# Extract and analyze Aquachu's stats hereExercise 3 — Complete Tournament Card
Perfect! You've registered Aquachu and reported its stats to the tournament official. Now, the official hands you a form and asks you to write all of Aquachu's information on it - this will become Aquachu's official fighting card! You have all the data ready: name, type, level, and stats. Your job is to make it look professional and impressive!
You can make it look professional by using:
- Decorative borders (╔═╗ ║ ╚═╝ ╠═╣) to frame the card
- F-strings to display the information
- Alignment with <X (like <25) to make everything line up nicely
# Aquachu's tournament data
name = "Aquachu"
type, level = "water", 18
attack, defense, speed = 75, 60, 85
average_stat = (attack + defense + speed) / 3
# Create Aquachu's beautiful fighting card here