Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Function basics
8. Using a function return value


You can assign the result of a function to a variable:

def factorial(number):
  score = 1
  while number > 1:
    score = score * number
    number = number - 1
  return score

result = factorial(5)

After the function returns, the result variable is assigned the value of factorial(5). If you print the value of the result, you get the 120 – the return value of this function with 5 passed as an argument. However, note that you don't have to assign the function's return value to a variable in order to use it later in your code:

user_number = int(input('Please provide a natural number: '))
print('The factorial for', user_number, 'is', factorial(user_number))


We've already created the factorial function for you. Assign the result of factorial(3) to a variable named a and factorial(4) to a variable named b. Then, print sum of these two variables.