Skip to content

Instantly share code, notes, and snippets.

@dasunsucharith
Created May 18, 2022 02:49
Show Gist options
  • Save dasunsucharith/2fd20268375211b4d814fa95fccd65ad to your computer and use it in GitHub Desktop.
Save dasunsucharith/2fd20268375211b4d814fa95fccd65ad to your computer and use it in GitHub Desktop.
CS50 2022 psets6 Cash Problem Solution
# TODO
from cs50 import get_float
# keep track of coins used
count = 0
while True:
change = get_float("Change owned: ")
if change > 0:
break
# round up to the nearest whole number
cent = round(change * 100)
while cent >= 25:
cent = cent - 25
count += 1
while cent >= 10:
cent = cent - 10
count += 1
while cent >= 5:
cent = cent - 5
count += 1
while cent >= 1:
cent = cent - 1
count += 1
print(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment