QuizzesAdvanced Python Control Flow Techniques
advanced
python

Advanced Python Control Flow Techniques

Explore complex control flow mechanisms in Python for backend development.

20 minutes 10 questions Pass at 70%
Time Limit
20 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

10 questions on Advanced Python Control Flow Techniques. Work through them here, then start the quiz to answer them and see your score.

  1. 1.What will be the output of the following code snippet? ```python def func(x): if x > 10: return x elif x > 5: return x + 5 else: return x - 5 result = func(7) print(result) ```

    • ANone
    • B7
    • C2
    • D12
  2. 2.Consider the following code. What will be the output? ```python for i in range(3): if i == 1: continue print(i) ```

    • A0 1 2
    • B0 1
    • C0 2
    • D1 2
  3. 3.What is the result of the following code? ```python x = 0 while x < 5: x += 1 if x == 3: break print(x) ```

    • A4
    • B0
    • C5
    • D3
  4. 4.What will the following code snippet output? ```python for i in range(4): for j in range(2): if i == j: break else: print(i) ```

    • A0 1 2 3
    • B2 3
    • C3
    • D0 1
  5. 5.What will be printed by this code? ```python try: x = 1 / 0 except ZeroDivisionError: print('Error') else: print('No Error') finally: print('Finally') ```

    • ANo Error Finally
    • BError Finally
    • CError
    • DFinally
  6. 6.Analyze the following code. What will be the output? ```python x = [1, 2, 3] for i in x: if i == 2: x.append(4) print(i) ```

    • A1 2 3 4
    • B1 2 3
    • C1 2 3 4 4
    • D1 2 3 4 3
  7. 7.What is the output of the following code? ```python x = 5 while x: x -= 1 if x == 2: continue print(x) ```

    • A4 3 1 0
    • B4 3 1
    • C4 3 2 1
    • D4 3 2 1 0
  8. 8.What will be the output of this code snippet? ```python x = 0 for i in range(5): if i % 2 == 0: x += 1 else: x += 10 print(x) ```

    • A8
    • B10
    • C15
    • D13
  9. 9.What will be printed by the following code? ```python for i in range(3): try: if i == 1: raise ValueError except ValueError: print('Caught') else: print('No Exception') ```

    • ACaught Caught Caught
    • BNo Exception Caught No Exception
    • CCaught No Exception
    • DNo Exception Caught
  10. 10.What will the following code output? ```python def recursive(n): if n == 0: return 1 else: return n * recursive(n - 1) print(recursive(3)) ```

    • A6
    • B3
    • C0
    • DNone