+ 1
Where is the mistake here?
2 Respostas
+ 6
The code doesn't print because it's stuck in an infinite loop. You're decreasing the value of x inside the loop only when x is even. If x is odd, it never gets decremented, leading to an infinite loop. To fix this, you should decrement x outside of the if statement like this:
x = 10
while x > 0:
if x%2 ==0:
print (str(x) + " is an even number .")
x -= 1
+ 2
I like to use "print()" statements to debug my code. Try "print(x)" right above your if statement and see what is happening with your code.