You can simply validate the choice by testing against the list, then print the topping string itself:
if customerSandwichtoppings in toppings:
print("Yes sir!\nHalf bread:", customerSandwichtoppings)
else:
print("Sorry sir, that's not a topping we have")
You can combine this with the bread size; ask for both once, then combine the strings; you can uppercase the first letter of the bread choice with str.title()
:
while True:
customerSandwichsize = input("What size do you want: " + str(size) + " ")
if customerSandwichsize in size:
break
print("Sorry sir, that's not a size we have")
print("Okay, a", customerSandwichsize, "bread for you")
while True:
customerSandwichtoppings = input("What toppings to you want: " + str(toppings) + " ")
if customerSandwichtoppings in toppings:
break
print("Sorry sir, that's not a topping we have")
print("Yes sir!\n" + customerSandwichsize.title() + " bread:", customerSandwichtoppings)
The while True:
loops keep asking the user for the right information; if the in
test is true a valid choice was made
If the user can pick more toppings, you'll have to keep a list and keep looping:
picked_toppings = []
while True:
customerSandwichtopping = input("What toppings to you want: " + str(toppings) + " ")
if customerSandwichtopping == 'done':
if not picked_toppings:
print("Sorry sir, you haven't picked any toppings yet")
continue
# at least one topic picked, the customer is allowed to be done,
# break out of the while loop.
break
if customerSandwichtopping not in toppings:
print("Sorry sir, that's not a topping we have")
continue
if customerSandwichtopping in picked_toppings:
print("Sorry sir, you already picked that topping")
continue
picked_toppings.append(customerSandwichtopping)
print("Sure thing sir. You can pick more toppings, or say 'done' when you're done.")
then print the list:
print("Yes sir!\n" + customerSandwichsize.title() + " bread:", picked_toppings)
Put together as a function that'd look like:
def sandwich_maker(size, toppings, sauce):
while True:
customerSandwichsize = input("What size do you want: {} ".format(size))
if customerSandwichsize in size:
break
print("Sorry sir, that's not a size we have")
print("Okay, a", customerSandwichsize, "bread for you")
picked_toppings = []
while True:
customerSandwichtopping = input("What toppings to you want: " + str(toppings) + " ")
if customerSandwichtopping == 'done':
if not picked_toppings:
print("Sorry sir, you haven't picked any toppings yet")
continue
# at least one topic picked, the customer is allowed to be done,
# break out of the while loop.
break
if customerSandwichtopping not in toppings:
print("Sorry sir, that's not a topping we have")
continue
if customerSandwichtopping in picked_toppings:
print("Sorry sir, you already picked that topping")
continue
picked_toppings.append(customerSandwichtopping)
print("Sure thing sir. You can pick more toppings, or say 'done' when you're done.")
print("Yes sir!\n" + customerSandwichsize.title() + " bread:", picked_toppings)