In [3]:
x = 2
In [4]:
y = x % 2
y
Out[4]:
0
In [5]:
if y == 0:
print(str(x) + " is an even number")
else:
print(str(x) + " is an odd number")
2 is an even number
Creating a function¶
In [6]:
def odd_even(x):
y = x % 2
if y == 0:
print(str(x) + " is an even number")
else:
print(str(x) + " is an odd number")
In [7]:
odd_even(5)
5 is an odd number