how to find total price
I don't know how to get the all total price of the product that the customer bought from my system. the price of each item I can get but the price of all the item that have been choose i can't get the output. I'm using python.
Below is my code:
#below is the price of products
shopping_cart = {}
option = 1
while option!= 0:
option = int(input("What type of milk you want to purchased: "))
if option == 1:
print("coke")
qnty = int(input("Enter the quantity: "))
total = qnty*8.49
elif option == 2:
print("dutch lady")
qnty = int(input("Enter the quantity: "))
total = qnty*8.50
elif option == 3:
print("fanta")
total = qnty*3.00
elif option == 4:
print("Yoghurt")
qnty = int(input("Enter the quantity: "))
total = qnty*16.50
elif option == 5:
print("pepsi")
qnty = int(input("Enter the quantity: "))
total = qnty*18.50
elif option == 6:
print("beer")
qnty = int(input("Enter the quantity: "))
total = qnty*20.70
else:
("Not found")
def totalcart (pr,qnty): #is my code correct here?
totalcart = (pr * qny)
return total
print("The total price in your cart is ", (total))
break
print("Come Again")
Just putting ("Not found")
as a statement doesn't print anything. You need to add your item total into total_cost
immediately after the print statement. There's no point defining a function, since you don't call the function. So, replace everything after that last "else:" with this:
else:
total = 0
print("Not found")
total_cost += total
print("The total price in your cart is RM ", total_cost)
print("Please Come Again")