# Chapter 4 Programming Exercise 7 # Discount table # Quantity Discount # 10-19 20% # 20-49 30% # 50-99 40% # 100 or more 50% def main(): # User enters number of packages bought quantity = input('Enter number of packages bought: ') # Discount percentage if quantity < 10: print 'No discount.' discount=1.0 elif quantity < 20: print 'Discount is 20%.' discount=0.8 elif quantity < 50: print 'Discount is 30%.' discount=0.7 elif quantity < 100: print 'Discount is 40%.' discount=0.6 else: print 'Discount is 50%.' discount=0.5 total(quantity, discount) def total (quantity, discount): # No discount price $99.00 # Full price before discount full_price = quantity * 99 # price with discount total_amount = quantity * discount * 99 print 'Amount of discount is ', full_price - total_amount print 'Total purchase price is ', total_amount main()
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