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...
Write a class called Item that has a string field called name and a double field...
Write a class called Item that has a string field called name and a double field called price and an integer field called quantity. In main, create a bag of type Item and place several item objects in the bag. Then in main calculate the total price of items purchased. You may remove each item and add the price to a total variable in a loop. The loop should end when the bag is empty. Using bag algorithms public final...
1. Create an ArrayListReview class with one data field of ArrayList and one with LinkedList with...
1. Create an ArrayListReview class with one data field of ArrayList and one with LinkedList with the generic type passed to the class. 2. Create a constructor that populate an array list and the LinkedList filled with the generic type through inserting new elements into the specified location index-i in the list. 3. You have been given the job of creating a new order processing system for the Yummy Fruit CompanyTM. The system reads pricing information for the various delicious...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class Zillion implements a decimal counter that allows numbers with an effectively infinite number of digits. Of course the number of digits isn’t really infinite, since it is bounded by the amount of memory in your computer, but it can be very large. 1. Examples. Here are some examples of how your class Zillion must work. I’ll first create an instance of Zillion. The string...
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...