Python Control Flow & Conditional Logic quiz

This quiz is designed to help you master the core concepts of control flow and conditional statements in Python. These features are essential for making decisions, executing code conditionally and guiding the logic of your programs.

Last Updated :
Discuss
Comments

Question 1

What is the purpose of the if statement in Python?

  •  To define a function

  • To declare a variable

  • To execute a block of code conditionally

  •  To create a loop

Question 2

Which of the following operators is used for equality comparison in Python?

  • ==

  • =

  •  !=

  • >

Question 3

What will be the output of the following code snippet?

x = 5
if x > 0:
   print("Positive")
else:
   print("Negative")
 

  • Positive

  • Negative

  • Zero

  • Error

Question 4

How do you represent the logical AND operator in Python?

  •  &&

  • and

  • AND

  •  &

Question 5

What is the purpose of the elif statement in Python?

  • To handle exceptions

  • To create a loop

  • To define a function

  • To check additional conditions after the initial if statement

Question 6

In Python, what is the purpose of the else statement within an if-else block?

  • To define a function

  • To check additional conditions

  • To execute a block of code when the if condition is false

  • To create a loop

Question 7

What is the output of the following code snippet?

x = 10
if x > 5:
   print("Greater than 5")
elif x > 8:
   print("Greater than 8")
else:
   print("Less than or equal to 5")
 

  • Greater than 5

  • Greater than 8

  • Less than or equal to 5

  • No output

Question 8

Which statement is used to exit a loop prematurely in Python?

  • break

  • exit

  • return

  • continue

Question 9

In Python, what is the purpose of the try-except block?

  • To create a loop

  • To check multiple conditions

  •  To handle exceptions

  • To define a function

Question 10

What is the output of the following code snippet?

for i in range(5):
   if i == 3:
       continue
   print(i)
 

  •  0 1 2 3 4

  • 0 1 2 4

  • 0 1 2

  • 0 1 2 3

There are 10 questions to complete.

Take a part in the ongoing discussion