Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Function basics
7. Functions with return values
Summary

Instruction

Good. Functions can also return some values. For instance, when you execute isnumeric(), the function returns either True or False.

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

The program above takes an input number and returns its factorial (e.g., for number = 4, the function will return 4*3*2*1 = 24). The return keyword terminates the function and makes it return the value specified after the return keyword to the caller.

Exercise

Write a function named return_bigger(a, b) that takes two numbers and returns the bigger one. If the numbers are equal, return 0.

Stuck? Here's a hint!

Use a simple if statement:

if a > b:
  return ...
elif b > a:
  return ...
else:
  return 0