+ 3

My while loop doesn't work

Hi! My while loop looks exactly like the correct answer, but it doesn't work. For some reason it says that there's no input or output, that I have to try again. Can someone please help, what should I do, is the "correct answer" wrong? x = 0 while x <= 10: if x%2 == 0: print (x) x += 1 This should print only numbers that are even

6th May 2022, 11:52 AM
Sanna
3 Answers
+ 5
x+=1 is out side while loop. so x not get updated in loop. hence infinite loop. Add it into loop.. Identation mistake..
6th May 2022, 12:15 PM
Jayakrishna šŸ‡®šŸ‡³
+ 1
Oh thank you, I have only programmed with C and Java where curly brackets are used so I didn't realize that indentation has such a huge impact!
6th May 2022, 1:47 PM
Sanna
+ 1
Yes, it's python way of making blocks, compare to c curly braces.. You're welcome..
6th May 2022, 1:49 PM
Jayakrishna šŸ‡®šŸ‡³