+ 2

What is the output of this code ? Please explain it

a=2 b=0 While(a or b) a -=1 Print (a)

8th Feb 2019, 3:10 PM
H.code
3 Antworten
8th Feb 2019, 3:33 PM
Hubert Dudek
Hubert Dudek - avatar
+ 3
In python, any numeric value of zero (e.g. 0, 0.0) is considered False. 1st iteration: while(2 or 0) //True decrement 2 by 1 print 1 2nd iteration: while(1 or 0) //True decrement 1 by 1 print 0 3rd iteration: while(0 or 0) //False loop stops so statements inside loop are not executed
8th Feb 2019, 6:44 PM
Lambda_Driver
Lambda_Driver - avatar
+ 1
you could try it in the playground.
8th Feb 2019, 3:32 PM
Bahhaⵣ
Bahhaⵣ - avatar