I am learning about records in my computing class, I understand that they are like a record in a data base. I was told to use namedtuples for this. But my code isn't working. I get a "keyword can't be expression" error when running it.
from collections import namedtuple
product = namedtuple("Product", "Product Name", "Stock Number", "Price", "Purchased")
def Setup(product):
shoppingBasket = []
shoppingBasket[0] = product("Product Name" = "USB cable", "Stock Number" = 624, "Price" = 1.74, "Purchased" = False)
shoppingBasket[1] = product("Product Name" = "HDMI adaptor", "Stock Number" = 523, "Price" = 5.00, "Purchased" = False)
shoppingBasket[2] = product("Product Name" = "DVD-RW pack", "Stock Number" = 124, "Price" = 10.99, "Purchased" = False)
return shoppingBasket
def Main():
shoppingBasket = Setup(product)
cart = []
for item in shoppingBasket:
addItem = raw_input("Would you like to buy this item? ")
if addItem == "yes":
shoppingBasket[item].Purchased = True
cart.append(shoppingBasket)
total = calculate(cart)
def calculate(cart):
total = 0
for item in cart:
total += item.Price
return total
It says the error is on line 7 where I set shoppingBasket[0] to what I think is a record. What is wrong here?