Quizz
The full text of this chapter, to read or revisit. To practise, do the exercises.
βΆ Do the exercisesExercise 1 β Variable assignment
Which operator is used to assign a value to a variable?
===->:Hint : The = operator is used for assignment. == is used for comparison.
Exercise 2 β Create a variable
Create a variable named codemon_health and assign it the int value 100.
Hint : Use snake_case for variable names and = for assignment.
Exercise 3 β Valid variable name
Which variable name follows Python's snake_case convention?
player_scorePlayerScoreplayer-scoreplayer scoreHint : snake_case uses lowercase letters with underscores between words.
Exercise 4 β Match values with types
Match each value with its correct type.
423.14"Hello"TrueintfloatstrboolExercise 5 β Variable reassignment
What happens to the previous value when you reassign a variable?
Hint : A variable can only hold one value at a time.
Exercise 6 β Basic operations
Fill in the blanks with the correct operators.
Hint : That's basic math.
Exercise 7 β Division types
What is the result of 7 // 2?
33.541Hint : // is integer division, it returns only the whole part.
Exercise 8 β Operators and names
Match each operator with its name.
**%///Exercise 9 β Type casting
What does float(5) return?
5.05"5.0"Hint : float() converts an integer to a decimal number.
Exercise 10 β Converting types
Convert the float 3.7 to an integer.
Hint : To cast to an integer, use int(). This will remove the decimal part.
Exercise 11 β Mixed operations
What type is the result of 5 + 2.0?
floatintstrHint : Python always returns the most precise type when mixing int and float.
Exercise 12 β Correct string
Which string is correctly written?
message = 'Hello world'message = 'Hello world"message = "Hello world'message = Hello worldHint : Strings must start and end with the same type of quotes.
Exercise 13 β Create strings
Complete to create a valid string with quotes inside.
Hint : Use double quotes to wrap a string containing single quotes.
Exercise 14 β Boolean syntax
Which is the correct way to write a Boolean in Python?
TruetrueTRUE"True"Hint : Booleans in Python start with a capital letter: True or False.
Exercise 15 β Naming errors
Match each incorrect variable name with its error.
3_playersplayer-namePlayer_Nameplayer nameExercise 16 β Type function
Which function shows the type of a variable?
type()show()typeof()getType()Hint : Use type(variable) to see the type of a variable.
Exercise 17 β Power and modulo
Complete the calculations.
Hint : ** is power, % is modulo, // is floor division and / is regular division.
Exercise 18 β Modulo result
What is the result of 15 % 4?
343.7511Hint : % is the modulo, it returns the remainder of a division.
Exercise 19 β Float to int
What is the result of int(7.9)?
787.97.0Hint : int() turns a number into an integer, it does not round, it basically removes the decimal part.
Exercise 20 β Multiple variables
Create two variables: attack with value 25 and defense with value 30.
Hint : Remember to use lowercase for variable names (snake_case).
Exercise 21 β Calculate results
Match each calculation with its result.
2 ** 420 // 620 % 620 / 616323.333...Exercise 22 β String with apostrophe
How to correctly create a string containing don't?
text = "don't"text = 'don't'text = don'ttext = "don't'Hint : Use double quotes to wrap a string containing an apostrophe (single quote).
Exercise 23 β Boolean values only
How many possible values can a Boolean have?
Hint : Booleans value are True and False.
Exercise 24 β Reassign value
Change the value of level from 1 to 2. The type of the variable should remain the same.
Hint : Use the same variable name with = to reassign a new value.
Exercise 25 β Type after operation
What type will x be after this code: x = 10 / 2?
floatintstrboolHint : Division / always returns a float.