In: Computer Science
Write functions:
i) One that prompts a user for 2 numbers.
ii) Adds the two numbers if they are even
iii) Multiplies the two numbers if they are odd
iv) Displays the appropriate output to the user
You are writing 4 functions and calling them to test functionality.
RUN in IDLE
#to user input
def get_input():
a= int(input("Enter first number"))
b= int(input("Enter second number"))
return a,b
#adding two numbers
def add(a,b):
return a+b
#Multiply two numbers
def multiply(a,b):
return a*b
#display result
def display(res):
print("result is",res)
#testing functionality
#call get_input
input1,input2= get_input()
if(input1%2==0 and input2%2==0):
#if both are even then add
output=add(input1,input2)
#display result
display(output)
elif (input1%2==1 and input2%2==1):
#if both are odd then product
output=multiply(input1,input2)
#display result
display(output)
else:
#assuming if either of them is odd and other is even then it is invalid
print("wrong input..")
in the programme I have considered if both are even then add ,if both are odd then product for other cases invalid input
ts..