1

I have a code for a self-service checkout:

price = {'meat': 3, 'bread': 1, 'potato': 0.5, 'water': 0.2}

def buy():
    pay = 0
    while True:
        enter = input('Что покупаем???\n')
        if enter == 'end':
            break
        pay += price[enter]
    return pay

buy()

I wanted the code to return the price by keys (I indicated the product names with the keys, and the price with the values), but the return function does not work and the program ends

2 Answers2

0

You are missing this part to obtain the result of your function.

total_price = buy()
porrokynoa
  • 42
  • 6
0

The only thing you are missing is to actually output the price you calculated. Right now the buy() function is returning pay, but you're not doing anything with the returned value.

The simples way is to just wrap your buy() function in a print statement:

print(buy())

If you want to be more fancy you can add some text around it:

totalPay = buy()
print("You have to pay " + str(totalPay) + " euros.")
Ada
  • 427
  • 2
  • 13