Skip to content

Instantly share code, notes, and snippets.

@Omi98
Created August 27, 2022 15:15
Show Gist options
  • Save Omi98/bdaf669e8762a29d95ed8cdb387d92e1 to your computer and use it in GitHub Desktop.
Save Omi98/bdaf669e8762a29d95ed8cdb387d92e1 to your computer and use it in GitHub Desktop.
cs50p Coke
# list of valid inputs
valid_input = [5, 10, 25]
# due amount
amount = 50
print("Amount Due:", amount)
# while loop
while True:
# ask user for input
# input must be integer
coin = int(input("Insert coin: "))
# check if input is valid
if coin in valid_input:
# print("Voilà")
# negative subtraction
if amount < coin:
amount = coin - amount
print("Change Owed:", amount)
else:
amount = amount - coin
if amount == 0:
print("Change Owed:", amount)
break
else:
print("Amount Due:", amount)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment