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. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

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.

x = 0 while x<=10: if x%2 == 0: print(x) x+=1

27th Feb 2022, 9:46 AM
Radhika Agarwal
3 Answers
+ 2
x = 0 while x<=10: x+=1 if x%2 == 0: print(x)
27th Feb 2022, 9:55 AM
NEZ
NEZ - avatar
+ 2
You need to increase x on each iteration – not only when x is even.
27th Feb 2022, 10:07 AM
Lisa
Lisa - avatar
+ 2
x = 0 while x<=10: print(x) x+=2
27th Feb 2022, 12:49 PM
HungryTradie
HungryTradie - avatar