WorksheetsControl Structures and Conditionals Quiz
Total questions: 15
Worksheet time: 8mins
What is a control structure?
A data type used in Python
A logical design that controls the order in which statements execute
A method for handling errors
A type of loop
Which symbol is used in a flowchart to represent a condition?
Rectangle
Oval
Diamond
Arrow
What is the purpose of the if statement?
To repeat a block of code
To handle exceptions
To execute code only when a condition is true
To define a function
Which of the following is the correct syntax for an if-else statement?
if condition code else code
if condition: code else: code
if condition code else: code
if condition: code else code
What will be the output of the following code if x = 3? if x > 5: print("x is greater than 5") else: print("x is not greater than 5")
x is greater than 5
x is not greater than 5
No output
Error
Which operator is used to check if two values are equal in Python?
=
==
!=
>=
In the code below, what is the role of HIGH_SCORE? HIGH_SCORE = 95 if average >= HIGH_SCORE: print("Congratulations!")
Variable
Constant
Function
Operator
What is the output if hours = 45 and pay_rate = 20? if hours > 40: overtime_hours = hours - 40 overtime_pay = overtime_hours * pay_rate * 1.5 gross_pay = 40 * pay_rate + overtime_pay else: gross_pay = hours * pay_rate
800
900
1100
1150
What does the following code do? password = input("Enter password: ") if password == "prospero": print("Password accepted.") else: print("Wrong password.")
Encrypts the password
Checks if the password is correct
Changes the password
Stores the password
Which statement is used to check multiple conditions in sequence?
if-if-if
if-else-else
if-elif-else
if-then-else
What will the following code print if age = 20? if age < 5: print("Child") else: print("Adult")
Child
Adult
What is the output of the following code if score = 85? if score >= 90: print("A") elif score >= 80: print("B") elif score >= 70: print("C") else: print("F")
A
B
C
F
Which of the following is a relational operator?
+
=
>=
and
What does the else clause do in an if-else statement?
Repeats the condition
Executes when the if condition is true
Executes when the if condition is false
Checks another condition
Which of the following is the correct way to check if x is between 10 and 20?
10 < x < 20
10 < x and x < 20
Both A and B
