I have modified the remainder variable's placement in my code ( from the main function to the amount_due(coin, amount_due) function), which eliminated the Type error, and set up some pseudocode to keep me on track and at least figure out where did I go wrong. What I am trying to do is create a code that will prompt the user to enter coins one at a time with the accepted denominations (hence coins list), and show the remainder amount due after they've entered a coin until the total price value has been met. This is what was assigned:
Suppose that a machine sells bottles of Coca-Cola (Coke) for 50 cents and only accepts coins in these denominations: 25 cents, 10 cents, and 5 cents.
In a file called coke.py, implement a program that prompts the user to insert a coin, one at a time, each time informing the user of the amount due. Once the user has inputted at least 50 cents, output how many cents in change the user is owed. Assume that the user will only input integers and ignore any integer that isn’t an accepted denomination.
coins = [25,10,5]
def main():
amount_due = 50
print(f"Amount Due: {amount_due}")
coin = evaluated(amount_due)
def evaluated(a):
while True:
coin = int(input("Insert Coin:").strip())
if coin != coins:
print(f"Please enter your coins in the following increments: {coins}")
return coin
elif coin == coins:
continue
def amount_due(coin, amount_due):
remainder = amount_due-coin
if remainder <= 0:
print(f"Change owed: {remainder}")
if remainder > 0:
print(f"Amount due: {remainder}")
return remainder
main()
My UPDATED code as requested (just removed the != and replaced it with not in):
coins = [25,10,5]
def main():
amount_due = 50
print(f"Amount Due: {amount_due}")
coin = evaluated(amount_due)
def evaluated(a):
while True:
coin = int(input("Insert Coin:").strip())
if coin not in coins:
print(f"Please enter your coins in the following increments: {coins}")
return coin
elif coin in coins:
continue
def amount_due(coin, amount_due):
remainder = amount_due-coin
if remainder <= 0:
print(f"Change owed: {remainder}")
if remainder > 0:
print(f"Amount due: {remainder}")
return remainder
main()