While loops | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

While loops

Hello, I'm stuck at this problem. Can somebody help? You are given a program that outputs all the numbers from 0 to 10. Change the code to make it output only the even numbers. We should use while... x = 0 while print(x) x += 1 That's what I wrote but it doesn't work x = 0 while x % 2 == 0 : print(x) x += 1

17th Apr 2021, 7:34 AM
Simone Bucci
Simone Bucci - avatar
1 Answer
0
If you use while x % 2 == 0, the loop will end when the value of x is 1. https://code.sololearn.com/cZx1YMs86Hbc/?ref=app
17th Apr 2021, 7:43 AM
Soumik
Soumik - avatar