Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Project: Change Calculator
- # Date: 13-08-2013
- # Lang: Python 3
- #
- # Last Edit: 13-08-2013
- # Version: 0.1
- #
- # Description:
- # Calculates change to be given back and outputs it as text
- print("CHANGE CALCULATOR")
- print("")
- # Input
- cost = float(input("Please enter the total costs: "))*100
- paid = float(input("Please enter the amount that was paid: "))*100
- change = round((paid - cost), 2)
- # Currency
- # List the units in the currency from largest to smallest movig down
- # And in the for of currency.append((value, "Name")) with value in cents
- currSign = '$'
- currency = []
- currency.append((10000, "One Hundred Dollar Bill" ))
- currency.append(( 5000, "Fifty Dollar Bill" ))
- currency.append(( 2000, "Twenty Dollar Bill" ))
- currency.append(( 1000, "Ten Dollar Bill" ))
- currency.append(( 500, "Five Dollar Bill" ))
- currency.append(( 100, "One Dollar Bill" ))
- currency.append(( 25, "Quarter" ))
- currency.append(( 15, "Dime" ))
- currency.append(( 5, "Nickel" ))
- currency.append(( 1, "Penny" ))
- numbers = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty"]
- # Change value calculation
- print("")
- if(change < 0):
- print("Ask for %s%f more from the customer" %(currSign, -change/100))
- elif(change == 0):
- print("Return of change not required")
- else:
- print("Return %s%f to the customer" %(currSign, change/100))
- print("")
- print("Return: ")
- # Change calculation
- for unit in currency:
- if(change >= unit[0]):
- amt = int(change/unit[0])
- change -= amt*unit[0]
- print("- %s %s%s" %(numbers[amt], unit[1], "s"*(amt > 1))) # Prints a dash, the amount as a word, the unit, and an s if the unit is plural
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement