Learn about Even or odd Program in Python using Function in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Even or odd Program in Python using Function
# Python program to check given number is an even or odd
# Returns true if num is even, else odd
def oddEven(num):
# check number is even or odd
return (num % 2 == 0)
# input from user
num = int(input('Enter a number: '))
# print result
if oddEven(num):
print('{0} is an even number'.format(num))
else:
print('{0} is an odd number'.format(num))
Output:
Enter a number: 4
4 is an even number
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : Python Program to check if a Number is Odd or Even