In: Computer Science
run in python IDLE 3.9.0
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.
Program Code Screenshot:
Sample Output:
The screenshots are attached below for reference.
Please follow them for proper indentation and output.
Please upvote my answer. Thank you.
Program code to
copy:
def read():
print("Enter two numbers:")
l=list(map(int,input().split()))#read two numbers and return
them
return l[0],l[1]
def add(n1,n2):
if n1%2==0 and n2%2==0:#add numbers if they are even
return n1+n2
else:
return None
def multiply(n1,n2):
if n1%2!=0 and n2%2!=0:#multiply two numbers if they are odd
return n1*n2
else:
return None
def display(a,m,n1,n2):
print("The numbers are:",n1," ",n2)#print the numbers
if a is None:
print("The addition is not possible")#print message when numbers
are not even
else:
print("The addition is :",a)#print appropriate results
if m is None:
print("The multiplication is not possible")#print message when
numbers are not odd
else:
print("The multiplication is :",m)
n1,n2=read()#call methods
a=add(n1,n2)
m=multiply(n1,n2)
display(a,m,n1,n2)