+ 1

Why does my code show it wrong

Question: write a code that takes a number as input and continues till it reaches 0 # take the number as input num = int(input()) #use a while loop for the countdown while num < 0: print(num) num-=1

25th Aug 2023, 12:04 PM
Mohammed Mahbeer Rahman
Mohammed Mahbeer Rahman - avatar
3 Answers
+ 4
Mohammed Mahbeer Rahman , Comparing operator should be: >= (the `=` is important if the value of 0 should be included in output) Currently the code runs an infinite loop.
25th Aug 2023, 12:36 PM
sandra
sandra - avatar
+ 2
Mohammed Mahbeer Rahman , The error in your code is the while loop condition. Instead of `while num < 0`, use this `while num > 0`. This will ensure that the loop continues until the value of `num` reaches 0.
25th Aug 2023, 12:37 PM
Darpan kesharwani🇼🇳[Inactive📚]
Darpan kesharwani🇼🇳[Inactive📚] - avatar
+ 1
@<{[《sandra 》]}>□■ Thank to you for reminding me about the mistake i've done May you be sucessful in this life
27th Aug 2023, 12:14 PM
Mohammed Mahbeer Rahman
Mohammed Mahbeer Rahman - avatar