Correcting errors
Seems there isn't any code for making the total not zero. AS well as no option to order more than one item.
menu = {"burger": 3.99,
"Chips": 1.99,
"drink": 0.99}
total = 0
#shows the user the menu and prompts them to select an item
print("Menu")
for k,v in menu.items():
print(k + " $" + str(v)) #why does v have "str" in front of it?
#ideally the code should prompt the user multiple times
item = input("Please select an item from the menu")
#code should add the price of the menu items selected by the user
print(total)
Making the total originaly zero and adding the prices to each item after they input it allows the user to make more than one order. Msg.lower makes it so all the text goes lowercase in case the user is using capitals. Def finish check allows the user to order more than one item.
affirmative = ['yes', 'Yes', 'yeah', 'Yeah', 'yup', 'Yup', 'y', 'Y', 'yea', 'Yea', 'mhm', 'Mhm', 'yep', 'Yep', 'Affirmative,' 'affirmative', 'sure', 'Sure', 'alright', 'Alright', 'okay', 'Okay', 'OK', 'ok', 'Ok']
negative = ['No', 'no', 'Nope', 'nope', 'N', 'n', 'Nah', 'nah', 'nuh-uh', 'Nuh-uh', 'negative', 'Negative']
#Capital and lowercase versions of all the responses are provided because this list was created before I knew how to force the string to be read as lower/uppercase
menu = {"Sandwhich": 3.99,
"Fries": 1.99,
"Water": 0.99}
total = 0 #price is defined later here just so that it is defined first
ordered = False
def finish(): #function to allow the user to order another item
global fin
print("Is your order complete?")
msg = input()
fin = msg.lower() #corrects for possible capitalized user response
def finishcheck():
roundtotal = round(total, 2) #rounding to prevent certain sum errors with floats
print("Your current total is $" + str(roundtotal) + ".")
finish() #see just above
if fin in affirmative: #using affirmative bank to understand user responses
print("Understood.")
return 0 #value to be read later (0 = stop)
elif fin in negative: #same but with negative
print("Understood.")
return 1 #value to be read later (1 = continue)
else:
print("Invalid response.")
finish() #repeating process when an invalid response is provided
def ordercheck():
global total
msg = input("Please select an item from the menu")
item = msg.capitalize()
for k,v in menu.items(): #for loop checks if input is one of the accepted dictionary keys
if item == k:
ordered = True
if k == "Fries":
print("You ordered fries.")
else:
print("You ordered a " + k.lower() + ".")
total += v
return 1
def order(): #defined as a function so that the process can be repeated
global ordered
print("-----MENU-----")
for k,v in menu.items(): #reprinting the menu for each order
print(k + " $" + str(v))
print("--------------")
if ordered == True:
print("What else would you like to order?")
if ordercheck() == 1:
if finishcheck() == 0:
return
else:
order()
else:
print("We don't serve that here.")
order()
order()
roundtotal = round(total, 2) #rounding to prevent certain sum errors with floats
print("Your total is $" + str(roundtotal) + ". Thank you for choosing Python's Pub.")