For a homework assignment, I created this function that will only give an output if you input in the following strings: "burger", "fries", "panini", and "salad".
def createOrder(food):
if food == 'burger':
print(['buns', 'patty', 'lettuce', 'pickles', 'tomato', 'cheese'])
elif food == "fries":
print(['potato', 'salt'])
elif food == 'panini':
print(['bread', 'ham', 'cheese'])
elif food == 'salad':
print(['greens mix', 'ranch', 'tomato'])
else:
food != 'burger', 'fries', 'panini', 'salad'
print("Invalid order")
Now I need to code another function that uses the createOrder() function to get the list of ingredients necessary for all the orders and return the number of each ingredient necessary to fulfill all the orders. eg. >>>gatherIngredients([‘burger’, ‘burger’, ‘panini’])
‘You need 2 buns, 2 patty, 2 lettuce, 2 pickles, 2 tomato, 3 cheese, 1 bread, 1 ham’
Here's my code so far on that:
def gatherIngredients(orders):
if len(items) == 0:
print('No orders to complete at this time')
items = []
counts = []
for order in orders:
order_items = createOrder(order)
for item in order_items:
index = -1
for i in range(len(items)):
if item == items[i]:
index = i
if index == -1:
items.append(item)
counts.append(1)
else:
counts[index] += 1
result = 'You need'
for i in range(len(items)):
result += str(counts[i])
result += " "
result += items[i]
if i < len(items) - 1:
result += ", "
return result
Can someone help me on this and fix my code? Only for the second function, however.