Videos
I didn't want to post a new answer but instead make a comment, but alas, not enough reputation.
I just wanted to add to Daemon Painter's answer and say that the final total bill also isn't working as it is multiplying a dict by an int.
What could work is to initialize out of the loop the total variable as well a new total_cost variable, and place:
total_cost += total
Inside the while loop but outside the if conditions. That way the last line can just be:
print("The total price of your basket is: ", total_cost)
Edit: the code, working as intended:
price = {"Lemonade": 1.50, "Coke": 2.00, "Fanta": 1.00, "Water": 0.50}
shopping_basket = {}
print("Welcome to the online drink store!\nThese are the drinks we offer\n1. Lemonade: £1.50\n2. Coke: £2.00\n3. Fanta £1.00\n4. Water: £0.50")
buy_another_flag = 1
total_cost, total = 0, 0
while buy_another_flag != 0:
option = int(input("Which drink would you like to purchase?: "))
if option == 1:
qnty = int(input("Enter the quantity: "))
total = qnty * 1.50
print("The price is: " + str(total))
elif option == 2:
qnty = int(input("Enter the quantity: "))
total = qnty * 2.00
print("The price is: " + str(total))
elif option == 3:
qnty = int(input("Enter the quantity: "))
total = qnty * 1.00
print("The price is: " + str(total))
elif option == 4:
qnty = int(input("Enter the quantity: "))
total = qnty * 0.50
print("The price is: " + str(total))
total_cost += total
buy_another_flag = int(input("Would you like another item? enter Yes (1) or No (0):"))
print("The total price of your basket is: ", total_cost)
You are looping indefinitely in the while loop.
Once you assigned option via User input here:
option = int(input("Which drink would you like to purchase?: "))
this condition is always fulfilled:
while option!= 0:
Here, you should not just print, but re-assign the option:
print("Would you like another item? enter Yes or No:")
something like this:
option = int(input("Would you like another item? enter Yes or No:"))
I hope this is pointing you in the right direction :)
(I've made assumptions on how you should have the code formatted in your original script. They might be wrong...)