Printing return value in function

Viewed 62504

The print(result) in my total function isn't printing my result.

Shouldn't the sums function return the result value to the function that called it?

This is my code:

def main():

  #Get the user's age and user's best friend's age.

  firstAge = int(input("Enter your age: "))
  secondAge = int(input("Enter your best friend's age: "))
  total(firstAge,secondAge)

def total(firstAge,secondAge):
  sums(firstAge,secondAge)
  print(result)

#The sum function accepts two integers arguments and returns the sum of those arguments as an integer.

def sums(num1,num2):
  result = int(num1+num2)
  return result

main()

I'm using Python-3.6.1.

2 Answers

You don't need the extra variable response, you can simply do:

print( total(firstAge,secondAge) )

Related