+ 1

Why the answer is 4 ?

It asks what is the answer i = 3 While i >=0 i = i - 1 Print(i) And it says the answer is 4

14th Oct 2019, 1:13 PM
ayan sinha
ayan sinha - avatar
7 Antworten
+ 5
The code you supplied here gives -1 as result.
14th Oct 2019, 2:06 PM
Lothar
Lothar - avatar
+ 3
Maybe 4 is how many times a number is printed: 2 1 0 -1
14th Oct 2019, 1:27 PM
AndreaC
AndreaC - avatar
+ 2
It can't be 4, because i gets lower not higher, so in the last loop we have: i = 0 (condition is satisfied) i = i - 1 ( so i = -1 ) And it stops there, output is -1, run it again.
14th Oct 2019, 1:17 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
We can't know the answer to a question you haven't provided... what was the question ?
14th Oct 2019, 1:35 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
But it says the answer is 4 With out the answer 4 I can not go farther and it's not accepting any other answer
14th Oct 2019, 1:24 PM
ayan sinha
ayan sinha - avatar
+ 1
Can you give us the specific question? Is it asking for what i is after the loop is done or how many times the while iterates through it?
14th Oct 2019, 1:33 PM
Odyel
Odyel - avatar
0
If it comes from a challenge in sololearn, you can report the bad answer.
16th Oct 2019, 9:18 AM
Fernando Pozzetti
Fernando Pozzetti - avatar