Quizz
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercisesExercise 1 — Valid Codémon Name Check
Check if the Codémon's name is valid (more than 3 characters).
Hint : len() count the number of characters in a string. Count the characters and compare with 3.
Exercise 2 — Battle Banner Creation
Create a battle banner by repeating decorations and adding the title.
Hint : Use * to repeat strings and + to concatenate them.
Exercise 3 — Codémon Welcome Message
Create a welcome message using an f-string with the trainer's name and level.
Hint : f-string format requires the prefix 'f' and curly braces for variables.
Exercise 4 — String Indexing
Match each string indexing expression on the left with the result on the right.
"Aquachu"[0]"Pyrochu"[-1]"Fire"[1:3]"Water"[:2]"A""u""ir""Wa"Exercise 5 — Type Conversion and Addition
What is the final value of total_score in this code sequence?
score = '10'
bonus = 5
total_score = int(score) + bonus
print(total_score)15105'105'ErrorHint : Think about type conversion and addition.
Exercise 6 — Type Conversion Result
What will be the result of: str(3.14) + '0'?
"3.140""3.14""3140"Hint : Think about string concatenation and type conversion.
Exercise 7 — String Slicing Result
What will be the result of: "Florachu"[2:6]?
"orac""lora""orach"Hint : Slicing starts at the first index and stops before the second index.
Exercise 8 — Advanced String Slicing
Match each slicing expression on the left with the result on the right.
"Python"[::2]"Hello"[::-1]"Codémon"[-3:]"Battle"[1:-1]"Pto""olleH""mon""attl"Exercise 9 — String Concatenation Welcome
Create a welcome message using string concatenation.
Hint : String concatenation is similar to math addition.
Exercise 10 — String Membership Check
What will print("chu" in "Aquachu") display?
TrueFalse"chu"Hint : The 'in' operator checks if a substring exists within a string.
Exercise 11 — String Slicing and Methods
Extract the first three characters.
Hint : Slicing uses square brackets and a colon to specify the range. The format is [start:end:step].
Exercise 12 — F-string Number Formatting
What will print(f"{3.14159:.2f}") display?
"3.14""3.142""3.1416""3"Hint : .Xf after a number means the number will be displayed with X digits after the decimal point.
Exercise 13 — Variable Types
Match variables on the left with their types on the right.
level = 42power = 3.14name = "Aquachu"rare = TrueintfloatstrboolExercise 14 — String Cleaning Result
What will be the final result after cleaning this messy name?
messy_name = " pYrOcHu "
clean_name = messy_name.strip().lower().capitalize()
print(clean_name)"Pyrochu""pyrochu""PYROCHU"" pYrOcHu "Hint : Follow each method step by step: strip removes spaces, lower makes lowercase, capitalize makes first letter uppercase.
Exercise 15 — String Multiplication
What happens when you multiply a string by a number in Python? Example: "hi" * 3
"hihihi""hi3""3hi"Hint : Think about string repetition in Python.
Exercise 16 — Password Validation
Check if the password is long enough and contains the required character.
Hint : The 'in' keyword allows you to check if a character is present in a string.
Exercise 17 — String Concatenation Result
What will be stored in message?
message = "Hello" + " " + "World"
"Hello World""HelloWorld""Hello World"Hint : String concatenation is similar to math addition.
Exercise 18 — Trainer Score Message
Create a message using an f-string.
Hint : Remember to use f prefix and curly braces.
Exercise 19 — String Operations Results
Match the expression from the left with the result from the right.
"Hello" + "!"str(42)len("Pyrochu")"Hi" * 2"Hello!""42"7"HiHi"Exercise 20 — Type Compatibility Error
What happens when you try to add a number and a string?
score = 42
message = score + " points""42 points""42points"Hint : Think about type compatibility, can you add a number and a string?
Exercise 21 — Score Conversion Fix
Convert score so we can print the message without errors.
Hint : Remember to convert numbers before concatenating.
Exercise 22 — String Comparison Result
What is the result of: "FIRE" == "fire".upper()?
TrueFalseError"FIRE"Hint : The upper() method converts the string to uppercase before comparison.
Exercise 23 — Type Search in Name
Check if the type name is contained in the Codémon's full name.
Hint : The 'in' operator checks if one string is contained within another.
Exercise 24 — String Methods Results
Match each string method on the left with the result on the right.
"Hello".lower()"pyrochu".upper()" hi ".strip()"abc".replace('b', 'B')"hello""PYROCHU""hi""aBc"Exercise 25 — Name Length Check
Check if the Codémon name has at least the minimum required length.
Hint : Having enough length means len() is greater than or equal to the minimum.