Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a program that reads a whole number and says if it is even or odd. What does it say for and for ?
n % 2 == 0 means that n is even.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. A number is even when the remainder after dividing by 2 is 0.
n = int(input("Type a whole number: "))if n % 2 == 0: shows even.else: shows odd.Check. leaves , so is even. leaves , so is odd.
Log in to join the discussion.
Loading…