Functions

4 / 5

Default parameters let you assign a default value to a function argument. This means that if the caller does not provide a value for that parameter, the default will be used automatically. It helps make functions more flexible and easier to use.

For example:

def greet(name="friend"):
 print(f"Hello, {name}!")
greet() 
greet("Alice")

The first function call falls back to the default value "friend" and prints Hello, friend. The second function call overwrites the default parameter value and prints Hello, Alice.

Default parameter values

Write a function print_receipt_line with three parameters item, price, and amount. The function should print a line as it would appear on a receipt. The amount of items should default to 1.

For example, print_receipt_line ('pen', 1.45, 2) should print 2 x pen - 1.45.

Congratulations!

You passed the !

Welcome!

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

Your email has been verified!