Learn about Check if the Number is Odd in Python using Function in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Check if the Number is Odd in Python using Function
# Python program to check given number is an odd or not using function
# Returns true if num is odd, else not odd
def isOdd(num):
return (num % 2 != 0)
# input
num = int(input('Enter a number: '))
# print result
if isOdd(num):
print(num,"is an odd number")
else:
print(num,"is not an odd number")
Output:
Enter a number: 5
5 is an odd 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 : Program to Check if the Number is Odd in Python