Functions

5 / 5

Python functions can return multiple values as a tuple. You can unpack these values when calling the function.

Example:

def calculate_circle(radius):
  area = 3.14 * radius ** 2
  circumference = 2 * 3.14 * radius
  return area, circumference

You can call the function and assign the two values to variables separated by commas, like so:

a, c = calculate_circle(5)

Now a will contain the area, and c the circumference.

Multiple return values

Write a function calculate_tip with arguments bill and tip_percentage. The tip_percentage must default to 15.

The function must return two numbers: the tipping amount and the total bill including tips.

Congratulations!

You passed the !

Welcome!

Would you like a guided tour on how to use Vibewise?

Your email has been verified!