0
python while loop
I have difficulties understanding how this code outputs the values below. Code: i = 0 x = 0 while i < 4: print(x) x+=i i+=1 Output: 0 0 1 3
3 Respostas
+ 4
Visualize your code execution
(Python, Java, C, C++, JavaScript, Ruby)
https://pythontutor.com
+ 1
i = 0
x = 0
while i < 4:
print(x)
#x=0,x=0,x=1,x=4
x+=i
#x=0 since i=0,now x=1,x=3
i+=1
#now i=1,i=2,i=3
"""Output:
0
0
1
3"""
0
Hope this helps you