Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a function called display _ charges that calculates the final bill for an online shopping site. The function should take the following arguments where

Design a function called display_charges that calculates the final bill for an online shopping site. The function should take the following arguments where numeric values are assumed to be non-negative:
the purchase price (ie. $ 15.99)
the tax rate (ie.8% tax rate)
a boolean value representing site membership - True if buyer is a member, False otherwise
a discount code that should be one of: FIRST_PURCHASE, FREQUENT_BUYER, NO_DISCOUNT. Any other values would not be valid discount codes.
the country being shipped to (ie. Canada)
The function should print a report of the charges according to the following rules:
if the buyer is a member or they are shipping within Canada they recieve free shipping
shipping is calculated as 10 percent of the amount before discounts and tax
the discounts codes should be applied to the amount of the purchase, to a minimum of 0, as follows:
FIRST_PURCHASE is $ 10 off the purchase price
FREQUENT_BUYER and they are a site member it is $ 2 off the purchase price
NO_DISCOUNT or an invalid discount code is $ 0 off the purchase price
tax is calculated on the amount after the discount is applied
For example, if the function was called as follows:
display_charges(22.0,8, False, 'FIRST_PURCHASE', 'Mexico')
The ouput should be in the exact format (notice each item is on a new line and prices printed to two decimal places):
price: $ 12.00
tax: $ 0.96
shipping: $ 2.20
total charge: $ 15.16

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions