This is my code about a simple bending machine
drinks = {"1. coke": 1000, "2.sprite": 800, "3.grape Juice": 600, "4.cocoa": 300}
drinks_name = list(drinks.keys())
prices = list(drinks.values())
input_money = int(input("insert money>> "))
print("1.coke, 2.sprite, 3.grape Juice, 4.cocoa")
user_input = int(input("choose a drink>> ")) - 1
while True:
if input_money < prices[user_input]:
pick = int(input(
f"You need more money! 1.choose another drink, 2.give up buying drinks, 3.{prices[user_input] - input_money} add more money "))
if pick == 3:
input_money = input_money + int(input("add more money>> "))
elif pick == 1:
user_input = int(input("choose drink again>> "))
elif pick == 2:
print("see u next time. Thx.")
break
else:
change = input_money - prices[user_input]
print(
f"get your {drinks_name[user_input]}, change is {change}!")
ask = input("continue? [Y/N] ")
if ask == "N" or ask == "n":
print(f"change is {change}. thx for using me.")
break
elif ask == "Y" or ask == "y":
input_money = change
user_input = int(input("choose a drink>> ")) - 1
else:
print("Answer in Y / N or y / n")
When I run this code, I found a problem.
When I put 400 and chose 600 of grape juice, terminal says that
the amount is not enough! 1.Choose another drink, 2.Give up buying a drink, or add 3.200 more!
If I choose number 1 here again (select another drink), and choose number 1 coke,
terminal says that you should add 400 instead of 600. What should I fix or add?
sorry for my english