0

I've written the following code but when i run check 50 I get errors as shown in this link.

I cannot understand what is wrong with my code as the output is exactly what is asked by the problem.

def main():
    amount_due = 50
    while amount_due > 0:
        print("Amount Due: ", amount_due)
        amount_due -= check_coins()
    print("Change Owed: ", abs(amount_due))

def check_coins():
    while True:
        coins = int(input("Insert Coin: "))
        if coins  == 25 or coins == 10 or coins == 5:
            break
    return coins

main()

1 Answer 1

0

My mistakes have been the following:

print("Amount Due: ", amount_due)

should be replaced with the following, where there is no space after the ":"

print("Amount Due:", amount_due)

Also, when inserted the wrong coin, my code asks "Insert Coin:" while the problem wants first to print "Amount Due:" and then to "Insert Coin:"

I couldn't find a solution the the last issue with the method of calling functions so I had to rewrite the code as follows:

amount_due = 50
while amount_due > 0:
    print("Amount Due:", amount_due)
    while True:
        coins = int(input("Insert Coin: "))
        if coins  == 25 or coins == 10 or coins == 5:
            break
        else:
            print("Amount Due:", amount_due)
    amount_due -= coins
print("Change Owed:", abs(amount_due))

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .