wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Control Structures and Conditionals Quiz

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is a control structure?

a)

A data type used in Python

b)

A logical design that controls the order in which statements execute

c)

A method for handling errors

d)

A type of loop

2.

Which symbol is used in a flowchart to represent a condition?

a)

Rectangle

b)

Oval

c)

Diamond

d)

Arrow

3.

What is the purpose of the if statement?

a)

To repeat a block of code

b)

To handle exceptions

c)

To execute code only when a condition is true

d)

To define a function

4.

Which of the following is the correct syntax for an if-else statement?

a)

if condition code else code

b)

if condition: code else: code

c)

if condition code else: code

d)

if condition: code else code

5.

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")

a)

x is greater than 5

b)

x is not greater than 5

c)

No output

d)

Error

6.

Which operator is used to check if two values are equal in Python?

a)

=

b)

==

c)

!=

d)

>=

7.

In the code below, what is the role of HIGH_SCORE? HIGH_SCORE = 95 if average >= HIGH_SCORE: print("Congratulations!")

a)

Variable

b)

Constant

c)

Function

d)

Operator

8.

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

a)

800

b)

900

c)

1100

d)

1150

9.

What does the following code do? password = input("Enter password: ") if password == "prospero": print("Password accepted.") else: print("Wrong password.")

a)

Encrypts the password

b)

Checks if the password is correct

c)

Changes the password

d)

Stores the password

10.

Which statement is used to check multiple conditions in sequence?

a)

if-if-if

b)

if-else-else

c)

if-elif-else

d)

if-then-else

11.

What will the following code print if age = 20? if age < 5: print("Child") else: print("Adult")

a)

Child

b)

Adult

12.

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)

A

b)

B

c)

C

d)

F

13.

Which of the following is a relational operator?

a)

+

b)

=

c)

>=

d)

and

14.

What does the else clause do in an if-else statement?

a)

Repeats the condition

b)

Executes when the if condition is true

c)

Executes when the if condition is false

d)

Checks another condition

15.

Which of the following is the correct way to check if x is between 10 and 20?

a)

10 < x < 20

b)

10 < x and x < 20

c)

Both A and B