In: Computer Science
Write functions in Python IDLE that do the following:
i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters.
ii) A function that takes 2 arguments and returns the difference,
iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both.
Python code:
#i)defining function to add
def add(num1,num2):
return num1+num2
#ii)defining function to find difference
def difference(num1,num2):
return num1-num2
#iii)defining function to find product of add and difference
function
def product():
#accepting first number
num1=int(input("Enter 1st number: "))
#accepting second number
num2=int(input("Enter 2nd number: "))
#printing product of add and difference
function
print(add(num1,num2)*difference(num1,num2))
#calling product function and testing
product()
Screenshot:
Input and Output: