Quizz

The full text of this chapter, to read or revisit. To practise, do the exercises.

β–Ά Do the exercises

Exercise 1 β€” Variable assignment

Which operator is used to assign a value to a variable?

Options
β€’ =
β€’ ==
β€’ ->
β€’ :

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?

Options
β€’ player_score
β€’ PlayerScore
β€’ player-score
β€’ player score

Hint : snake_case uses lowercase letters with underscores between words.

Exercise 4 β€” Match values with types

Match each value with its correct type.

Items to match
β€’ 42
β€’ 3.14
β€’ "Hello"
β€’ True
Definitions
β€’ int
β€’ float
β€’ str
β€’ bool

Exercise 5 β€” Variable reassignment

What happens to the previous value when you reassign a variable?

Options
β€’ It is lost and replaced by the new value
β€’ It is stored in memory
β€’ You get an error
β€’ Both values coexist

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?

Options
β€’ 3
β€’ 3.5
β€’ 4
β€’ 1

Hint : // is integer division, it returns only the whole part.

Exercise 8 β€” Operators and names

Match each operator with its name.

Items to match
β€’ **
β€’ %
β€’ //
β€’ /
Definitions
β€’ Power
β€’ Modulo
β€’ Integer division
β€’ Division

Exercise 9 β€” Type casting

What does float(5) return?

Options
β€’ 5.0
β€’ 5
β€’ An error
β€’ "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?

Options
β€’ float
β€’ int
β€’ str
β€’ Error

Hint : Python always returns the most precise type when mixing int and float.

Exercise 12 β€” Correct string

Which string is correctly written?

Options
β€’ message = 'Hello world'
β€’ message = 'Hello world"
β€’ message = "Hello world'
β€’ message = Hello world

Hint : 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?

Options
β€’ True
β€’ true
β€’ TRUE
β€’ "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.

Items to match
β€’ 3_players
β€’ player-name
β€’ Player_Name
β€’ player name
Definitions
β€’ Starts with a number
β€’ Contains a hyphen
β€’ Uses capital letters
β€’ Contains a space

Exercise 16 β€” Type function

Which function shows the type of a variable?

Options
β€’ 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?

Options
β€’ 3
β€’ 4
β€’ 3.75
β€’ 11

Hint : % is the modulo, it returns the remainder of a division.

Exercise 19 β€” Float to int

What is the result of int(7.9)?

Options
β€’ 7
β€’ 8
β€’ 7.9
β€’ 7.0

Hint : 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.

Items to match
β€’ 2 ** 4
β€’ 20 // 6
β€’ 20 % 6
β€’ 20 / 6
Definitions
β€’ 16
β€’ 3
β€’ 2
β€’ 3.333...

Exercise 22 β€” String with apostrophe

How to correctly create a string containing don't?

Options
β€’ text = "don't"
β€’ text = 'don't'
β€’ text = don't
β€’ text = "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?

Options
β€’ 2 (True and False)
β€’ 3 (True, False and None)
β€’ Infinite
β€’ 4 (True, False, Yes, No)

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?

Options
β€’ float
β€’ int
β€’ str
β€’ bool

Hint : Division / always returns a float.

Back to the course