## Python

Moderators: None (Apply to moderate this forum)
Number of posts: 1165

This Forum Only

Software Sales (Python) Posted by Gerbol on 18 Feb 2012 at 7:31 PM
A software company sells a package that retails for \$99. Quantity discounts are given
according to the following table:
Quantity Discount
10–19 20%
20–49 30%
50–99 40%
100 or more 50%

This is what I have done. Please correct me because I cannot run Python.
Thanks

# Named constants
RETAIL_PRICE = 99

# main function
def main():
# Local variables
quantity = 0
fullPrice = 0.0
discountRate = 0.0
discountAmount = 0.0
totalAmount = 0.0

# Get number
quantity = int(input("Enter the number of packages purchased: "))

# Calculate the discount rate
if quantity > 99:
discountRate = 50/100
elif quantity > 49:
discountRate = 40/100
elif quantity > 19:
discountRate = 30/100
elif quantity > 9:
discountRate = 20/100
else:
discountRate = 0

# Calculate the full price
fullPrice = quantity * RETAIL_PRICE

# Calculate the discount amount
discountAmount = fullPrice * discount

#Calculate the total amount
totalAmount = fullPrice - discountAmount

# print results
showPurchase(discountAmount, totalAmount)

# The showPurchase function accepts discountAmount, totalAmount as
# arguments and displays the amounts
def showPurchase(discountAmount, totalAmount):
print ("Discount Amount: \$", format(discountAmount, '.2f'))
print ("Total Amount: \$", format(totalAmount, '.2f'))

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic