Skip to content

Instantly share code, notes, and snippets.

@Edmundworks
Created July 7, 2020 13:26
Show Gist options
  • Save Edmundworks/54dd5d2984dae23dc5d586420c733c2f to your computer and use it in GitHub Desktop.
Save Edmundworks/54dd5d2984dae23dc5d586420c733c2f to your computer and use it in GitHub Desktop.
Short solution for CS50 Cash in Python
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