+ 12

Why the value i is 6 after "finished"?

i = 1 while i <=5: print(i) i = i + 1 print("Finished!")

21st Dec 2017, 1:02 PM
Nilavarasan
Nilavarasan  - avatar
5 ответов
+ 7
When i is 5, it still satisfies the condition of the loop so it is incremented to become 6. 😉
21st Dec 2017, 1:04 PM
blackcat1111
blackcat1111 - avatar
+ 2
it's states that I is either equal to or less than 5......so just add it up with 1
23rd Jan 2018, 7:42 AM
meren lkr
meren lkr - avatar
+ 2
because when i=5 , the condition is true, then the loop execute i=5+1.
26th Jan 2018, 5:56 AM
Genaro Coronel
Genaro Coronel - avatar
0
because when i=5 condition satisfied.print 5 and the value of I increment to 6(i=6).then value of is I=6 the condition fail.then print rest of code.
3rd Feb 2018, 3:13 AM
Narender
0
Hasta el valor de 5 la condición de bucle es verdadera. Este se frena o se para cuando i tomé el valor de 6 , no antes. Por eso el valor final de I es. 6
15th Apr 2018, 3:00 PM
Luis Gonzalez
Luis Gonzalez - avatar