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

Question

What is the output of the code? X=0 While x<5: X = x+2 print (x) The answer is 6 why?

6th Apr 2020, 8:17 PM
Thiratikan
5 Answers
+ 4
The answer comes 6 because before exiting the loop it adds 2 in 4.
6th Apr 2020, 8:20 PM
...
+ 4
There is an increment of 2. So it will start from 0 and will be incremented to 2,4 & finally 6.
6th Apr 2020, 8:24 PM
...
+ 4
Run this code so you might get an idea what I'm trying to say https://code.sololearn.com/cUaf8cS8d0gd/?ref=app
6th Apr 2020, 8:35 PM
...
0
why 4? can it be 3, 2, or 1?
6th Apr 2020, 8:21 PM
Thiratikan
0
i still dont get why x = 4 can I put 3? cause 3<5 is also ture so the answer can be 5?
6th Apr 2020, 8:31 PM
Thiratikan