Python

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

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
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
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.