Created
July 7, 2020 13:26
-
-
Save Edmundworks/54dd5d2984dae23dc5d586420c733c2f to your computer and use it in GitHub Desktop.
Short solution for CS50 Cash in Python
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 variables | |
total, count = change * 100, 0 | |
# calculate count of coins | |
for x in [25, 10, 5, 1]: | |
while total >= x: | |
total -= x | |
count += 1 | |
# print result | |
print(f"{count}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment