-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04-product.py
More file actions
executable file
·43 lines (40 loc) · 1.22 KB
/
04-product.py
File metadata and controls
executable file
·43 lines (40 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Product(object):
def __init__(self,price,name,weight,brand,cost):
self.price = price
self.name = name
self.weight = weight
self.brand = brand
self.cost = cost
self.status = "For Sale"
def sell(self):
self.status = "Sold"
return self
def addTax(self,tax):
return self.cost+tax
def Return(self,reason):
if type(reason) != str:return
reason = reason.lower()
if reason == "defective":
self.status = reason
self.price = 0
elif reason == "in box":
self.status = "For Sale"
elif reason == "opened":
self.status = "Used"
self.cost *= .20
return self
def displayInfo(self):
print " Price:{}\n Name:{}\n Weight:{}\n Brand:{}\n Cost:{}".format(self.price,self.name,self.weight,self.brand,self.cost)
return self
soap = Product(5,"Soap",2,"Dove",5)
print soap.addTax(12)
soap.sell()
print vars(soap).items()
soap.status = "ASKDJH" # Checking privacy
print vars(soap).items()
soap.Return("in box")
print vars(soap).items()
print "\n"
soap.sell().Return("opened").sell().displayInfo()
# for k,v in vars(soap).items():
# print k,v