Created
August 27, 2022 15:15
-
-
Save Omi98/bdaf669e8762a29d95ed8cdb387d92e1 to your computer and use it in GitHub Desktop.
cs50p Coke
This file contains 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
# 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