SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Decision Structures And Boolean Logic
Exercise:
Programming Exercises
Question:8 | ISBN:9780132576376 | Edition: 2

Question

A software company sells a package that retails for $99. Quantity discounts are given according to the following table:

Write 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.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

COMPLETE PYTHON CODE:

# Ask the user to enter the number of packages purchased
package_purchased = int(input("Enter number of packages purchased: "))

# Calculate the discount
if package_purchased >= 10 and package_purchased <= 19:
    discount = 0.2 * package_purchased * 99
elif package_purchased >= 20 and package_purchased <= 49:
    discount = 0.3 * package_purchased * 99
elif package_purchased >= 50 and package_purchased <= 99:
    discount = 0.4 * package_purchased * 99
elif package_purchased >= 100:
    discount = 0.5 * package_purchased * 99
else:
    discount = 0

# Calculate total purchase after discount
total_purchase = package_purchased * 99 - discount

# Display the results
print("Discount: $" + str(discount))
print("Total purchase after discount: $" + str(total_purchase))

OUTPUT 1:

Enter number of packages purchased: 150
Discount: $7425.0
Total purchase after discount: $7425.0

OUTPUT 2:

Enter number of packages purchased: 25
Discount: $742.5
Total purchase after discount: $1732.5

 

0 0

Discussions

Post the discussion to improve the above solution.