+ 2

I don't understand how the answer is 4

How many numbers does this code print? i = 3 while i>=0: print(i) i = i - 1 Kindly explain how the answer is "4"

23rd Aug 2017, 6:35 PM
Olanipekun John Funsho
5 Réponses
+ 4
output is 4 because i=3; while i>=0 so 3>0 it goes in the while body and print 3 then i=i-1 i=3-1=2 so now the value of I is 2 so it again check the condition of while loop then it will print 2 2>0 so it is again true it goes in the while body and become i=i-1 which is i=2-1=1 so now value of I =1 and it print 1 now again 1>0 so it goes in while body and become i=1-1=0 so now the value of I become 0 and 0will print and then it check the condition it is true so it will print 0 now I =i-1 which is i=0-1=-1 now check the condition of while loop it is false so as a output four values came which are 3 2 1 0 so the output is 4
23rd Aug 2017, 6:46 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 4
Unless you have bad math, there are 3-0+1=4 numbers printed
23rd Aug 2017, 11:01 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
It prints: 3 2 1 0 which is 4 numbers
23rd Aug 2017, 6:42 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
hey guys 😂😂😂 you have said everything.
27th Aug 2017, 1:24 AM
Abdallah Kezire
Abdallah Kezire - avatar