Python Core - 26.2 Practice "Call It Even" | Sololearn: Learn to code for FREE!


Python Core - 26.2 Practice "Call It Even"

I'm not sure what to do here: 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. Any integer that can be divided exactly by 2 is an even number. x = 0 while x <= 10: print(x) x += 1

7/19/2021 5:11:42 PM


3 Answers

New Answer


Add a condition inside the loop: if x % 2 == 0: print(x) x += 1


You could also in that example change your iterator so that it counts by every two numbers counting only the even ones.


You'll want to create a condition inside of the loop that's dividing x by 2 and seeing if there's a remainder or not. IF the remainder is 0 THEN it's an even number, ELSE it's an odd number. So if it's even, print the variable, ELSE increase x by 1 without printing and let it loop again. Hope that helps explain it a bit.