Advertisement
Guest User

ChangeCalc.py

a guest
Sep 25th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. # Project:  Change Calculator
  2. # Date:     13-08-2013
  3. # Lang:     Python 3
  4. #
  5. # Last Edit:        13-08-2013
  6. # Version:          0.1
  7. #
  8. # Description:
  9. # Calculates change to be given back and outputs it as text
  10.  
  11. print("CHANGE CALCULATOR")
  12. print("")
  13.  
  14. # Input
  15. cost = float(input("Please enter the total costs: "))*100
  16. paid = float(input("Please enter the amount that was paid: "))*100
  17. change = round((paid - cost), 2)
  18.  
  19. # Currency
  20. # List the units in the currency from largest to smallest movig down
  21. # And in the for of currency.append((value, "Name")) with value in cents
  22. currSign = '$'
  23. currency = []
  24.  
  25. currency.append((10000, "One Hundred Dollar Bill"    ))
  26. currency.append(( 5000, "Fifty Dollar Bill"          ))
  27. currency.append(( 2000, "Twenty Dollar Bill"         ))
  28. currency.append(( 1000, "Ten Dollar Bill"            ))
  29. currency.append((  500, "Five Dollar Bill"           ))
  30. currency.append((  100, "One Dollar Bill"            ))
  31. currency.append((   25, "Quarter"                    ))
  32. currency.append((   15, "Dime"                       ))
  33. currency.append((    5, "Nickel"                     ))
  34. currency.append((    1, "Penny"                      ))
  35.  
  36. numbers = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty"]
  37.  
  38. # Change value calculation
  39. print("")
  40. if(change < 0):
  41.     print("Ask for %s%f more from the customer" %(currSign, -change/100))
  42. elif(change == 0):
  43.     print("Return of change not required")
  44. else:
  45.     print("Return %s%f to the customer" %(currSign, change/100))
  46. print("")
  47. print("Return: ")
  48.  
  49. # Change calculation
  50. for unit in currency:
  51.     if(change >= unit[0]):
  52.         amt = int(change/unit[0])
  53.         change -= amt*unit[0]
  54.         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