def addition(num1, num2):
answerAdd=num1+num2
print(answerAdd)
def subtraction(num1, num2):
answerSub=num1-num2
print(answerSub)
def main():
num1=int(input('Enter the first number: '))
num2=int(input('Enter the second number: '))
print(addition, subtraction)
main()
I’ve tried renaming the call function and can’t get it to return the arithmetic,.
>Solution :
A couple of problems:
-
printandreturnare not interchangeable. When you need your function to return a value you usereturn, when you merely need it to print something than useprint. Your first two functions should be returning the values they calculate so that yourmain()function canprint()them. -
When calling your functions you have to give them values for the arguments you defined. Your
additionandsubtractionfunctions both have two arguments.
def addition(num1, num2):
answerAdd=num1+num2
#Problem 1: changed to `return`
return answerAdd
def subtraction(num1, num2):
answerSub=num1-num2
#Problem 1: changed to `return`
return answerSub
def main():
num1=int(input('Enter the first number: '))
num2=int(input('Enter the second number: '))
#Problem 2: changed to send `num1` and `num2` as arguments to both functions
print(addition(num1, num2), subtraction(num1, num2))
main()