Please explain this code. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please explain this code.

x = 3 y = 1 while x>0: y=y+x x=x-2 print (y)

4th Aug 2020, 6:02 AM
Allamprabhu Hiremath
2 Answers
+ 1
Hi Allamprabhu Hiremath x=3 y=1 while x>0: y=y+x x=x-2 #print(y) First, 3>0; so y=1+3=4 Second, 1>0; so y=4+1=5 Third, -1<0; so loop stops. Therefore, print(y)=5
4th Aug 2020, 6:26 AM
Baratov Hojiakbar
Baratov Hojiakbar - avatar
+ 2
Thank you
4th Aug 2020, 6:28 AM
Allamprabhu Hiremath