I'm quite new to programming.
My problem is that my if statement is getting an IndexError. So I put my if statement into another cell and tried it with a different list and it works fine. What did I do wrong?
from datetime import datetime
import math
def GroceryReceipt():
grocery = [["bread", 3], ["eggs", 3], ["soda", 7], ["chips", 3], ["beef", 8]]
amountGroceries = int(input("Input the amount of food you wish to buy: "))
userGroc = []
for i in range(amountGroceries):
buyGroceries = input("Pick some foods: ")
userGroc.append(buyGroceries)
for j in range(len(grocery)):
if(len(userGroc) < j):
break
else:
print("$",grocery[j][1])
if(userGroc[j] in grocery[j][0]):
add = grocery[j][1] + grocery[j][1]
tax = math.pi/100 * add
total = tax + add
round(total, 2)
x = datetime.today()
print(total, x)
GroceryReceipt()