Reputation: 21
I am working on the following problem:
Write a shopping cart class to implement a shopping cart that you often find on websites where you could purchase some goods. Think about what things you could store in a cart and also what operations you could perform on the cart. To simplify matters, you could consider the website to be an electronics e-store that has goods like flat-panel TVs, radios, iPods, camcorders, and so on.
This is my code so far:
class ShoppingCart(object):
def __init__(self, name = "", address = ""):
self.items = []
self.total = 0
self.shopper = name
self.address = address
def get_address(self):
return self.address
def get_address(self,address):
self.address = address
def add_item(self, T):
"Add tuple(name, quantity, price, ID)"
self.items.append(T)
self.total = sum(t[2] for t in self.items)
def delete_item(self, T):
"Delete tuple(name, quantity, price, ID)"
if T in self.items:
self.items.remove(T)
self.total = sum([t[2]] for t in self.items)
def print_cart(self):
print("\n cart:")
print("\t", "Item", \t\, "price", "quantity")
for T in self.items:
print("\t", T[0],"\t", T[2], "\t", T[1])
print("\n Total:", self.total)
def test_cart():
"Demonstrate use of class"
s = ShoppingCart('Rich')
s.add_item(("iPod Nano", 1, 150.00, '12345'))
s.add_item(("The Holiday (DVD)", 2, 18.00, '14443'))
s.set_address('123 Timber, St. Louis, MO, 63130')
s.print_cart()
test_cart()
I get an error saying:
File "<ipython-input-5-b4071917f558>", line 27
print("\t", "Item", \t\, "price", "quantity")
^
SyntaxError: unexpected character after line continuation character
Does anyone know why this error is occurring? Thank you in advance!
Upvotes: 0
Views: 319
Reputation: 53
Try to add colon:
print("\t", "Item", "\t", "price", "quantity")
And you could use a simple way:
print("\t Item \t price quantity")
Upvotes: 1
Reputation: 570
The answer lies in the error message given. You cannot print out \t\
. I think you meant "\t"
.
Upvotes: 0