+ 5
Why the answer is 0?
a=2 b=0 while(a or b): a-=1 print(a) and Why when b is not 0 Time limit exceeded occurred ?
2 Respuestas
+ 2
value of a is 0 because print is outside of while loop and it will print final value of a which is 0.
in first loop: a=2-1=1
second loop: a=1-1=0
now both a and b are 0 so loop will terminate.
+ 2
In python a variable is false when it's equal to 0, so the while loop will run until both a and b are equal to 0. Therefore a will be equal to 0 in the end as it's decremented in the loop.