# ------------------------------------------------------------ #Student: Austin Wells #Class: CIS122 #Date: 4/14/2015 #Program Title: Chapter 4 Programming Excercise 7.py #(Software Sales) #Program Description: The program prompts the user for a number of software #packages and reutrns the total amount of the purchase based on that number. # ------------------------------------------------------------ SOFTWARE_BASE_COST = 99 # Prints out the quantity, discount cost, and total cost. def printDiscountAndTotal(discountCost,quantity): print 'With a quantity of {} the discount is ${:0,.2f} \nTotal Purchase Amount: ${:0,.2f}' .format(quantity, discountCost, calculateTotalCost(discountCost,quantity)) # prompts user for input. def promptForNumber(strPrompt): userInput = int(raw_input(strPrompt + ": ")) print '{}' .format(userInput) return userInput #calculates the discount based on the quantity def calculateDiscount(quantity): if(quantity <10): discountCost = 0 elif (quantity >= 10 and quantity <= 19): discountCost = .2 * SOFTWARE_BASE_COST elif (quantity >= 20 and quantity <= 49): discountCost = .3 * SOFTWARE_BASE_COST elif (quantity >= 50 and quantity <= 99): discountCost = .4 * SOFTWARE_BASE_COST else: discountCost = .5 * SOFTWARE_BASE_COST return discountCost # calculate the total cost def calculateTotalCost(discountCost,quantity): totalCost = SOFTWARE_BASE_COST - discountCost return totalCost #main driver function def main(): try: userInput = promptForNumber("Please enter the number of packages to purchase") except (ValueError): print '\n\nInvalid input. You have entered a non integer. Please enter an integer' except (EOFError): print '\n\nInvalid input. You have forgotten to add input. Please Reset program and Please enter an integer' else: discountCost = calculateDiscount(userInput) printDiscountAndTotal(discountCost,userInput) 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