Beginner · Conditions · 53 of 264
Even or odd
Read a whole number and say whether it is even or odd.
Input: a whole number. Output: even or odd
Examples
Input
4
Output
even
Input
7
Output
odd
Input
0
Output
even
Input
-3
Output
odd
One more test checks other inputs when you press Check.
Stuck? The idea behind conditions
An if statement runs its indented lines only when the condition is true; elif tries another condition; else catches everything left.
Compare with == (equal), != (not equal), <, <=, >, >=, and join conditions with and, or, not.
n = int(input())
if n > 0:
print("positive")
elif n < 0:
print("negative")
else:
print("zero")Watch for: = gives a value, == compares. And the order of elif matters: the first true one wins, so test the narrow case first.