# Software discount calculator # by Robert Layton SOFTWARE_PRICE = 99.00 #CONSTANT value for the software price # FUNCTIONS # Return a string with the percentage (float value) as a percentage def percentageString(num, trailingNumbers): return str(num*100)[:4 + (trailingNumbers-1)] + '%' # MAIN PROGRAM # Welcome and prompt user for input print 'Welcome to the software quantity discount calculator.' quantity = input('Enter the number of software packages purchased.') # Intitialize discount variable discount = 0.0 # Determine discount based on quantity if (quantity >= 100): discount = 0.50 elif (quantity >= 50): discount = 0.40 elif (quantity >=20): discount = 0.30 elif (quantity >= 10): discount = 0.20 # Print results subtotal = quantity * SOFTWARE_PRICE print '\n ----- RECEIPT ------' print 'Software purchased:', quantity print 'Subtotal: $' + "{:,.2f}".format(subtotal) print 'Total discount: $' + "{:,.2f}".format(subtotal * discount), '(' +percentageString(discount,2) +')' print 'Total price: $' + "{:,.2f}".format(subtotal - (subtotal * discount))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question