+ 2

No out put - Python

Why am I getting "No Output" in the result? i = 10 while i > 0: if i == 3: continue else: print (i) i -= 1

12th Oct 2020, 5:34 AM
Bishwajit Khanra
Bishwajit Khanra - avatar
3 Answers
+ 3
Your code got stuck in an infinite loop, Code Playground terminates your code because of this behaviour. When <i> value reaches 3 the condition `i == 3` evaluates to true, and `continue` is executed. But <i> value is not decremented, so when the loop goes back for another round <i> value remains to be 3. This is where the loop becomes infinite. Simply add `i -= 1` before the `continue` statement and it'll work.
12th Oct 2020, 6:11 AM
Ipang
+ 1
And if you want to see the output before reaching 3, you have to flush it at each print: print(i, flush=True)
12th Oct 2020, 6:17 AM
Bilbo Baggins
Bilbo Baggins - avatar
+ 1
If u try it in a standered python compiler like pycharm or visual studio code ,you will get output: 10 9 8 7 6 5 4 but then it will cause infinite loop but in sololearn it will give no output.
12th Oct 2020, 6:24 AM
The future is now thanks to science
The future is now thanks to science - avatar