- 2
Why the answer is 6? Python Beginners
27.1 exercise 4/5 I=0 X=0 While I < 4: X+= I I+=1 Print(x)
7 RĂ©ponses
+ 7
You can check quiz comments to understand the quiz clearly.
For example, I got this from the top comment.
x =0 , i =0
while i<4
x+ = i , i+ = 1
1st loop
x = 0 + 0 = 0
i = 0 + 1 = 1
2nd loop
x = 0 + 1 = 1
i = 1 + 1 = 2
3rd loop
x = 1 + 2 = 3
i = 2 + 1 = 3
4th loop
x = 3 + 3 = 6
i = 3 + 1 = 4( i not less than 4 and program stop here )
So, the value of x is 6.
+ 3
because in the loop x get sum of each values of l: 0 + 1 + 2 + 3 == 6
+ 2
x += l is same as x = x + l
0
Thanks visph!
0
Ohhhhhhh
0
Thanks Simba
0
If you want some other value in the X variable you can replace the l with some other value