Question

3.Write a method, addItem, for the class Shop that adds an item to the shop, the...

3.Write a method, addItem, for the class Shop that adds an item to the shop, the items should be stored in a python type list.

An example of usage is the following:
--------------------------------------------------------------
>>> myShop = Shop("Bezza", "Salmiya", (10.5, 6.3, 20.1) )
>>> myShop.addItem("Rice")
>>> myShop.addItem("Stew")
>>> myShop.addItem("Shrimp")

2.Write a class, called Shop, that has a constructor, __init__, method that takes in the name of the shop, the location of the shop, and the dimensions of the shop being a width length and height of the shop as a 3-way tuple.

An example of how a shop is instantiated is the following:
---------------------------------------------------------------------------------
>>> myShop = Shop("Bezza", "Salmiya", (10.5, 6.3, 20.1) )

Homework Answers

Answer #1

class Shop:#creating a class with name shop
def __init__(self, name, location,dimension):#contructor
    #assigning values
    self.name = name
    self.location = location
    self.dimension=dimension
    self.item_list=[]#creating empty list
def addItem(self,item):#method to additems
     self.item_list.append(item)#storing items in list
#creating object and calling contructor with parameters
myShop = Shop("Bezza", "Salmiya", (10.5, 6.3, 20.1) );
#calling additems function
myShop.addItem("Rice")
myShop.addItem("Stew")
myShop.addItem("Shrimp")
print("Shop name:",myShop.name,"\nlocation:",myShop.location,"\ndimensions:",myShop.dimension)#displaying
print("Items:",myShop.item_list)#printig items in list

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions