Computer Science

How many times will the following code be executed?

a = 5
while a > 0:
    print(a)
print("Thank You")
  1. 5 times
  2. Once
  3. Infinite
  4. None of these

Python Control Flow

2 Likes

Answer

Infinite

Reason — The code will result in an infinite loop because the value of a is never modified within the loop. The condition a > 0 will always be true, causing the print(a) statement to be executed indefinitely without changing the value of a.

Answered By

2 Likes


Related Questions