Skip to content

Instantly share code, notes, and snippets.

@Nehadsys
Created October 26, 2022 12:00
Show Gist options
  • Save Nehadsys/d41a10f9144f898d2eec4c216cfd552f to your computer and use it in GitHub Desktop.
Save Nehadsys/d41a10f9144f898d2eec4c216cfd552f to your computer and use it in GitHub Desktop.
Greedy Algorithm Python
amountRequired = 150 # <---can be changed to desired user input.
amountReturned = 0
counter_25 = 0
counter_10 = 0
counter_5 = 0
counter_1 = 0
while amountRequired >= 25:
amountRequired -= 25
counter_25 += 1
while amountRequired >= 10:
amountRequired -= 10
counter_10 += 1
while amountRequired >= 5:
amountRequired -= 5
counter_5 += 1
while amountRequired >= 1:
amountRequired -= 1
counter_1 += 1
print("____________________________________")
print("Amount of times the Racks have been used:")
print("25 Rack:",counter_25)
print("10 Rack:",counter_10)
print("5 Rack:",counter_5)
print("1 Rack:",counter_1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment