So im coding a shopping basket and its printing the elif statement after some of the items have been entered like "ham". Why?
Ive already tried adding the while loop into the items list but this hasnt worked.
print("What would you like? We have:")
## A function to call anywhere throughout the code to be able to print
the item list
def item_List():
print(" - Milk")
print(" - Bread")
print(" - Butter")
print(" - Salt")
print(" - Pepper")
print(" - Ham")
print(" - Steak")
print(" - Banana Bunch")
print(" - Apple Tray")
print(" - Grapes")
print(" - Winegums")
print(" - Black Jacks")
print(" - Sugar")
print(" - Honey")
print(" - Tea Bags")
print(" - Coffee")
()
## Function caller
item_List()
## Variable set to a list for future appends
items = []
total = 0
addmore = True
while addmore == True:
print("Add an item or type stop.")
userInput = input()
if userInput.lower() == "stop":
addmore = False
else:
if userInput.lower() == "milk":
total += 1.55
if userInput.lower() == "bread":
total += 1.82
if userInput.lower() == "butter":
total += 1.29
if userInput.lower() == "salt":
total += 1.20
if userInput.lower() == "pepper":
total += 1.20
if userInput.lower() == "ham":
total += 1.99
if userInput.lower() == "steak":
total += 3.99
if userInput.lower() == "banana bunch":
total += 2.25
if userInput.lower() == "apple tray":
total += 1.52
if userInput.lower() == "grapes":
total += 1.41
if userInput.lower() == "winegums":
total += 0.85
if userInput.lower() == "black jacks":
total += 0.85
if userInput.lower() == "sugar":
total += 2.95
if userInput.lower() == "honey":
total += 0.85
if userInput.lower() == "tea":
total += 2.85
if userInput.lower() == "coffee":
total += 3.05
elif userInput not in items:
print("Please enter a valid item.")
## List append for user to change their shopping basket by adding items
to their basket
items.append(userInput)
print("Item added. Basket Total:","£",round(total,3))
## This prints the of their basket/list
print("\n--- Your Shopping List ---")
for i in items:
print(i.title())
## This prints the total of their basket/list
print("Total: £"+str(total))
the output shouldnt show "please enter a valid item", it should just add that item and ask for another input.
Aucun commentaire:
Enregistrer un commentaire