Python Conditionals and Loops Challenge Quiz

Test your understanding of Python's conditional statements and looping constructs with these challenging, concept-driven questions.

  1. Nested If-Else Evaluation

    What is the output of the following code snippet?nx = 1ny = 2nif x u003E 0:n if y u003E 2:n print('A')n else:n print('B')nelse:n print('C')

    1. C
    2. B
    3. A B
    4. No output
    5. A
  2. While Loop Termination

    Given the code: count = 0nwhile count u003C 5:n count += 2n if count == 4:n breaknelse:n print('End')nWhat is printed after execution?

    1. Break
    2. End
    3. None
    4. 4
    5. No output
  3. For Loop Unpacking

    What will the following code output?nfor a, b in [(1,2), (3,4), (5,6)]:n if b % 2 == 0:n print(a)nelse:n print(0)

    1. 1n0
    2. 1n3n5
    3. 1n3n5n0
    4. 1n5n0
    5. 1n5
  4. Continue Impact

    How many times does 'Hello' print?nfor i in range(5):n if i == 2:n continuen print('Hello')

    1. 4
    2. 2
    3. 0
    4. 5
    5. 3
  5. Pass Statement Usage

    In which scenario would using a pass statement be most appropriate?

    1. To raise an exception
    2. To skip the rest of a loop iteration
    3. To terminate a loop early
    4. To initialize a variable
    5. To provide a syntactically empty block
  6. Break with Else

    What is the output?nfor i in range(3):n if i == 1:n breaknelse:n print('Done')

    1. Done
    2. 1
    3. 1 Done
    4. Nothing is printed
    5. LoopError
  7. If-Elif-Else Ordering

    Given the code:nx = 10nif x u003E 5:n print('High')nelif x u003E 3:n print('Medium')nelse:n print('Low')nWhat is printed?

    1. High Medium
    2. Medium High
    3. Low
    4. High
    5. Medium
  8. Short-Circuit Evaluation

    Which value does this code assign to 'result'?nresult = False or True and False

    1. True
    2. False True
    3. Tralse
    4. None
    5. False
  9. Loop Variable Mutation

    Given:nnums = [1, 2, 3]nfor num in nums:n num += 10nprint(nums)nWhat does nums look like after executing this code?

    1. [11, 12, 13]
    2. [1, 2, 13]
    3. [11, 2, 3]
    4. [1, 2, 3]
    5. [1, 12, 3]
  10. While Loop Else Branch

    What does this code print?ni = 0nwhile i u003C 3:n i += 1nelse:n print(i)

    1. None
    2. 1
    3. 0
    4. 2
    5. 3
  11. Multiple Elif Handling

    Consider:nx = 5nif x == 3:n y = 1nelif x == 5:n y = 2nelif x == 5:n y = 3nWhat is the value of y after execution?

    1. 3
    2. 2
    3. 5
    4. None
    5. 1
  12. Truthiness in If Statements

    Which of the following will cause the if branch to execute?nx = ''nif x:n print('Yes')nelse:n print('No')

    1. x = 0
    2. x = []
    3. x = ''
    4. x = None
    5. x = 'Python'
  13. Range Function in For Loops

    How many times does the body of this loop run?nfor i in range(2, 10, 3): print(i)

    1. 4
    2. 2
    3. 1
    4. 0
    5. 3
  14. Loop with Continue and Break

    What is the output?nfor i in range(5):n if i % 2 == 0:n continuen if i == 3:n breakn print(i)

    1. 1
    2. 1n3n5
    3. 1n2
    4. 1n2n3
    5. 1n3
  15. Logical Operators Precedence

    What will be the result of this statement?nresult = not True or False and True

    1. True and False
    2. False
    3. None
    4. not True
    5. True