5. Even or odd
Your program reads one line holding a whole number. Print even if the number is even, or odd if it is odd, in
lower case.
A number is even when it divides by 2 with nothing left over, and odd when 1 is left over. This works the same for zero and for negative numbers: 0 and -8 are even, and -3 is odd.
Example 1
7oddExample 2
10evenExample 3
0evenConstraints
- The number is a whole number from -1,000,000,000 to 1,000,000,000.
- Print nothing else. A prompt inside
input()is fine: the tests leave it out of the output.
Submit also runs 4 more tests you can't see.
Practises If / Elif / Else (lesson 8).
n % 2is the remainder after dividingnby 2:0for an even number and1for an odd one.- It works for zero and negative numbers too:
0 % 2is0, so 0 is even, and in Python-3 % 2is1, so -3 is odd. - Use
if n % 2 == 0:to print"even", andelse:to print"odd", both in lower case.
Solve it without hints for 3 stars, with hints for 2, after seeing the solution for 1.
One way to solve it, once you've had a go.
Solving it after seeing the solution earns 1 star.
Your Submits show here, with their code, so you can go back to one. They stay in this browser.
# Read one whole number. Print "even" if it is even, # or "odd" if it is odd. n = int(input())
Run your code to see how it does on the test cases, or Submit to check every test.