def find(num): # password logic here if num%2 == 0: numtype="even" else: numtype = "odd" return numtypenum = int(input("Enter the number: ")) # 1. Take her inputnumtype = find(num) # 2. Speak to the find functionprint("Given number is",numtype). # 3. Publish if the number is also or odd

You are watching: How to check if a number is even in python

coder# python challenge07.py enter the number: 5Given number is oddcoder# python challenge07.py get in the number: 8Given number is even
Explanation:-input() duty is provided to take user inputfind() function is called to to examine if a number is off/even. This duty returns numtype together odd/evenAt last, publish if the offered number is odd/even

solution #2

Avoid usage of else block by assigning a default value (odd) to numtype

def find(num): # code logic right here numtype = "odd" if num%2 == 0: numtype="even" return numtypenum = int(input("Enter the number: ")) # take your inputnumtype = find(num) # call the find functionprint("Given number is",numtype) # print if the number is also or odd
coder# python challenge07.py enter the number: 5Given number is oddcoder# python challenge07.py go into the number: 8Given number is even

def find(num): # code logic right here if num%2 == 0: return "even" return "odd"num = int(input("Enter the number: ")) # take your inputnumtype = find(num) # contact the find functionprint("Given number is",numtype) # print if the number is even or odd
coder# python challenge07.py go into the number: 5Given number is oddcoder# python challenge07.py get in the number: 8Given number is even an individual Moderator   Tim West
The bitwise-and operator & behavior is trivia, yet it"s useful due to the fact that the bitwise operators tend to be consistent across many programming languages. are you certain you want to hide this comment? it will become hidden in her post, but will quiet be clearly shows via the comment"s permalink.