1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Python for Developers

Connected

Exercise

Calculating a discount

You're building a feature that calculates discounted prices for an online store. You want to be able to set different discount amounts and control whether prices are rounded to look cleaner in the app.

In this exercise, you will create a custom function that handles these requirements using default and keyword arguments.

Instructions

100 XP
  • Define the calculate_discount() function with default arguments for discount_percent(15) and round_result(True).
  • Round the result to two decimal places inside the if statement.
  • Call the function, setting discount_percent to 25 and round_result to False.