Question

A software company sells a package that retails for $99. Quantity
discounts are given below:
Quantity Discount
10–19 20%
20–49 30%
50–99 40%
100 or more 50%
Design a program that asks the user to enter the number of packages purchased. The program should then display the amount of the discount (if any) and the total amount of the purchase after the discount.

Answers

Here is a Python program that implements the described functionality:

```python
def get_discount_rate(num_packages):
if 10 <= num_packages < 20:
return 0.2
elif 20 <= num_packages < 49:
return 0.3
elif 50 <= num_packages < 99:
return 0.4
elif num_packages >= 100:
return 0.5
else:
return 0


def calculate_discount(num_packages, retail_price):
discount_rate = get_discount_rate(num_packages)
discount = retail_price * num_packages * discount_rate
return discount


def calculate_total(num_packages, retail_price):
discount = calculate_discount(num_packages, retail_price)
total = retail_price * num_packages - discount
return total


if __name__ == "__main__":
retail_price = 99

num_packages = int(input("Enter the number of packages purchased: "))
discount = calculate_discount(num_packages, retail_price)
total = calculate_total(num_packages, retail_price)

print(f"Discount: ${discount:.2f}")
print(f"Total amount: ${total:.2f}")
```

When the user runs this program, they will be prompted to enter the number of packages purchased. The program will then calculate the discount and total amount of the purchase, and display these values to the user.

Related Questions