Quiz

What is the output of the given code?
while true:
  print('a')
  break

Error a Infinite loop true is not same as True. In Python boolean value is True with the uppercase T

What is the output of the given code?
while True:
  print('a')
break

Error a Infinite loop break is not inside the while block and you get an infinite loop. As such you cannot have a 'break' outside of a loop. However even before the interpreter can find out about this problem, it is busy looping endlessly through the while loop which comes before the break

What is the output of the given code?
a = 0
while a < 10:
   a + 2
print(a)

10 12 Infinite Loop a+2 is not saved back to 'a'. So a's value never changed. If you replace a = a + 2 or a += 2 then it prints 10

Exercise

results matching ""

    No results matching ""