Challenge 2: Python Essentials

Complete another challenge to practice what you’ve learned about Python essentials so far.

Function to calculate a receipt

Let’s assume the following scenario: You’re a loyal customer at a store that’s offering the following discounts to its loyal customers:

  • For a purchase between 0 and 50 CAD, you get a 10 percent discount.
  • For a purchase between 51 and 100 CAD, you get a 20 percent discount.
  • For a purchase of more than 100 CAD, you get a 40 percent discount.
  • On Mondays, if you spend more than 50 CAD, you get an additional 10 CAD off.

For this task, you need to write a function to calculate how much the customer’s purchase will actually cost after discounts and return that value.

Tip: A good way to handle this problem is to develop the logic first. Take a pen and a notebook and do the calculations by hand, if required. Test your function for 51, 50, 100, 101 using the for loop at the end.

Input

The input will contain two values:

  1. An integer value of the purchase cost.
  2. A boolean value—either it’s Monday or not. True is for Monday, and False is not Monday.

Output

A floating value of total cost after discounts.

Sample input

cost=50, is_monday=True

Sample output

45.0

Get hands-on with 1400+ tech skills courses.