Where is the mistake here? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
17th Sep 2023, 10:34 PM
bensouag abdou
2 Answers
+ 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
18th Sep 2023, 1:01 AM
Liam Park
Liam Park - avatar
+ 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.
17th Sep 2023, 10:57 PM
Aaron Lee
Aaron Lee - avatar