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
convert to python 3 from python 2 from Tkinter import * # the blueprint for a...
convert to python 3 from python 2 from Tkinter import * # the blueprint for a room class Room(object): # the constructor def __init__(self,name,image): # rooms have a name, exits (e.g., south), exit locations (e.g., to the south is room n), # items (e.g., table), item descriptions (for each item), and grabbables (things that can # be taken and put into the inventory) self.name = name self.image = image self.exits = {} self.items = {} self.grabbables = [] # getters...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT