Python Control Flow & Conditional Logic quiz

Last Updated :
Discuss
Comments

Question 1

What is the purpose of the if statement in Python?

  • A

     To define a function

  • B

    To declare a variable

  • C

    To execute a block of code conditionally

  • D

     To create a loop

Question 2

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

  • A

    ==

  • B

    =

  • C

     ===

  • D

    >

Question 3

What will be the output of the following code snippet?

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

    Positive

  • B

    Negative

  • C

    Zero

  • D

    Error

Question 4

How do you represent the logical AND operator in Python?

  • A

     &&

  • B

    and

  • C

    AND

  • D

     &

Question 5

What is the purpose of the elif statement in Python?

  • A

    To handle exceptions

  • B

    To create a loop

  • C

    To define a function

  • D

    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?

  • A

    To define a function

  • B

    To check additional conditions

  • C

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

  • D

    To create a loop

Question 7

What is the output of the following code snippet?

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

    Greater than 5

  • B

    Greater than 8

  • C

    Less than or equal to 5

  • D

    No output

Question 8

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

  • A

    break

  • B

    exit

  • C

    return

  • D

    continue

Question 9

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

  • A

    To create a loop

  • B

    To check multiple conditions

  • C

     To handle exceptions

  • D

    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)
 

  • A

     0 1 2 3 4

  • B

    0 1 2 4

  • C

    0 1 2

  • D

    0 1 2 3

There are 10 questions to complete.

Take a part in the ongoing discussion