Skip to content

Instantly share code, notes, and snippets.

@Edmundworks
Created July 6, 2020 23:09
Show Gist options
  • Save Edmundworks/0a018a6db8599cc59fa9cdc1e4d8a723 to your computer and use it in GitHub Desktop.
Save Edmundworks/0a018a6db8599cc59fa9cdc1e4d8a723 to your computer and use it in GitHub Desktop.
from cs50 import get_float
# Get positive float from user
while True:
change = get_float("Change owed: ")
if change > 0:
break
# declare counters
quarters, dimes, nickels, pennies = 0, 0, 0, 0
# make total
total = change * 100
# quarters
while True:
total -= 25
quarters += 1
if total < 26:
break
# dimes
while True:
total -= 10
dimes += 1
if total < 11:
break
# nickels
while True:
total -= 5
nickels += 1
if total < 6:
break
# pennies
pennies = int(total)
# add them up
coins = quarters + dimes + nickels + pennies
print(f"Quarters are {quarters}")
print(f"Dimes are {dimes}")
print(f"Nickels are {nickels}")
print(f"Pennies are {pennies}")
print(f"{coins}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment