Read number 1 problem then solve it. Your answer should be like number 2 2 Assig
ID: 3827016 • Letter: R
Question
Read number 1 problem then solve it. Your answer should be like number 22 Assignment #3-Retail (Due Thursday, April 27th @11:59pm) write a class named Retailutem, which should have the following data attributes: item description, units inventory, and price. The RetailItem class should have an init method that creates these attributes. It should also possess the necessary accessor (getters) and mutator etters) methods as appropriate. After this class is created save the file as retail itempy. Afterwards, create another file called testpy and write a program that prompts the user for the number of items to be purchased. These items should be treated as object instances. After the number the of items has been inputted by the user, the program should prompt the user to provide item name (ex shoes, Jeans, Shirts, Jackets, etc), the unit number can make up a number), and item price (you can (you program should make up a price) for each item. Next, the compute the total cost of the entered items based on their prices. Finally, the program should list the items and their respective data attribute values (item number, description, unit, and price)
Explanation / Answer
#retail_item.py
class RetailItem:
def __init__(self,name,qty,price):
self.name = name
self.qty = qty
self.price = price
def getName(self):
return self.name
def getQuantity(self):
return self.qty
def getPrice(self):
return self.price
def setName(self,name):
self.name = name
def setQuantity(self,qty):
self.qty = qty
def setPrice(self,price):
self.price = price
def __str__(self):
return "Discription : "+self.name+" Unit# "+str(self.qty)+" Price: "+str(self.price)+" "
#test.py
def test():
itemList = []
total = 0
numOfItem = int(raw_input("Enter the number of items to be purchased:"));
i= 0
while(i<numOfItem):
name = raw_input(" Enter the name of item #"+str(i+1)+":")
unit = int(raw_input("Enter unit number of item :"))
price = float(raw_input("Enter the price of this item :"))
total = total+price
item = RetailItem(name,unit,price)
itemList.append(item)
i=i+1
print " Total cost of these items is : "+str(total)+" "
i=1
for item in itemList:
print "Item#"+str(i)+" "+str(item)
i=i+1
test()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.