fork download
  1. def main():
  2.  
  3. denominations = [20, 10, 5, 1, .25, .10, .05, .01]
  4. used_denom = []
  5. amount_denom = []
  6.  
  7. user_input = float(input('enter a dollar amount: '))
  8.  
  9. #Keep asking user to re-enter input until they enter a value (0-200)
  10. while user_input < 0 or user_input > 200:
  11. user_input = float(input('re-enter a dollar amount: '))
  12.  
  13. #Traverse the list to breakdown the user_input into denominations.
  14. remainder = user_input
  15. for d in denominations:
  16. num_denom = int(remainder / d)
  17.  
  18. if num_denom > 0:
  19.  
  20. used_denom.append(d)
  21.  
  22. amount_denom.append(num_denom)
  23.  
  24. #Avoid dividing by a float (prevents .01 issue from occurring)
  25. remainder = (remainder*100) % (d * 100) / 100
  26.  
  27. #Traverse the amount_denom list and print the output to be formatted a certain way.
  28. for i in range(len(amount_denom)):
  29.  
  30. print("{0: 2d}{1:8.2f}".format(amount_denom[i],used_denom[i]),end = "")
  31. print("s" if amount_denom[i] > 1 else "")
  32.  
  33.  
  34. main()
Runtime error #stdin #stdout #stderr 0s 9992KB
stdin
Standard input is empty
stdout
enter a dollar amount: 
stderr
Traceback (most recent call last):
  File "./prog.py", line 34, in <module>
  File "./prog.py", line 7, in main
EOFError: EOF when reading a line