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
Write a Python class, Flower, that has 3 instance variables name, num_petals and price which have...
Write a Python class, Flower, that has 3 instance variables name, num_petals and price which have types str, int and float. Your class must have a constructor method to initialize the variables to an appropriate value, and methods for setting the value of each instance variable (set methods) and for retrieving the instance variable values (get methods). You can use the credit card code we looked at for assistance.
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...
      MK Restaurant: Branding of Thai-Style Hotpot The restaurant industry is one of the most...
      MK Restaurant: Branding of Thai-Style Hotpot The restaurant industry is one of the most competitive in Thailand. With a large number of players ranging from restaurants in five-star hotels, global fast-food chains to small stalls along the streets and everything in between, the Thais are spoiled for choice. In addition, as the world becomes globalized, consumers are familiar with international dishes and would not hesitate to try new offerings from the other side of the globe. As a...