How is the answer 6? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How is the answer 6?

i = 0 x=0 while i<4: x+=i i+=1 print(x) # i don't understand how the answer is 6, anyone please help me.

9th Jun 2022, 7:25 PM
Aditya Aryan
Aditya Aryan - avatar
3 Answers
+ 2
1st round. x+=i, i+=1 // x = 1, i =1 2nd round. x+=i(1), i+=1 // x = 2, i =2 3rd round. x+=i(2), i+=1 // x = 3, i = 3 4th round. x+=1(3), i+=1 // x = 6, i =4
9th Jun 2022, 7:35 PM
Justice
Justice - avatar
+ 2
Because, x is increased by 1, then 2, and finally 3.
9th Jun 2022, 7:33 PM
Jan
Jan - avatar
0
Its gonna take some time for me to process it. Thanks btw
10th Jun 2022, 2:59 AM
Aditya Aryan
Aditya Aryan - avatar