Created
July 6, 2020 23:09
-
-
Save Edmundworks/0a018a6db8599cc59fa9cdc1e4d8a723 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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