3.9k views
0 votes
create a module called quantityDiscount. The module has one input parameter, which is the number of packages purchased. In the module, the amount of the discount and the total amount of the purchase after the discount are calculated, then displayed. A package sells for $99, and discounts are: • less than 10 packages purchased: no discount • 10-19 packages purchased: 20% discount • 20-49 packages purchased: 30% discount • 50-99 packages purchased: 40% discount • 100 or more packages purchased: 50% discount

1 Answer

4 votes

def calculate_discount_and_total(packages_purchased):

package_price = 99 # Price of one package

discount = 0 # Initialize the discount to 0%

if packages_purchased < 10:

discount = 0

elif 10 <= packages_purchased <= 19:

discount = 0.20 # 20% discount

elif 20 <= packages_purchased <= 49:

discount = 0.30 # 30% discount

elif 50 <= packages_purchased <= 99:

discount = 0.40 # 40% discount

else:

discount = 0.50 # 50% discount

total_amount = packages_purchased * package_price * (1 - discount)

return discount, total_amount

# Example usage:

packages_purchased = int(input("Enter the number of packages purchased: "))

discount, total_amount = calculate_discount_and_total(packages_purchased)

print(f"Discount: {discount * 100}%")

print(f"Total amount after discount: ${total_amount:.2f}")

User Matt Lynch
by
8.0k points

No related questions found