-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmarketplace.py
73 lines (55 loc) · 1.94 KB
/
marketplace.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class Marketplace:
def __init__(self):
self.listings=[]
def add_listing(self,new_listing):
self.listings.append(new_listing)
def remove_listing(self,item):
self.listings.remove(item)
def show_listings(self):
for listing in self.listings:
print(listing)
class Art:
def __init__(self,artist,title,medium,year,owner):
self.artist=artist
self.title=title
self.medium=medium
self.year=year
self.owner=owner
def __repr__(self):
return "{artist}. \"{title}\". {year}, {medium}, {name}, {location}.".format(artist=self.artist, title=self.title, year=self.year, medium=self.medium, name=self.owner.name, location=self.owner.location)
class Listing:
def __init__(self,art,price,seller):
self.art=art
self.price=price
self.seller=seller
def __repr__(self):
return "{art} ,{price}.".format(art=self.art,price=self.price)
class Client:
def __init__(self,name,location,is_museum):
self.name = name
self.location=location
self.is_museum=is_museum
def sell_artwork(self,artwork,price):
if self == artwork.owner:
new_listing=Listing (artwork,price,self)
veneer.add_listing(new_listing)
def buy_artwork(self,artwork):
if artwork.owner != self:
art_listing =None
for listing in veneer.listings:
if listing.art == artwork:
art_listing=listing
break
if art_listing!= None:
art_listing.art.owner = self
veneer.remove_listing(art_listing)
###################################
veneer=Marketplace()
edytta = Client("Edytta Halpirt","Private Collection", False)
moma = Client("The MOMA","New York", True)
girl_with_mandolin= Art("Picasso, Pablo","Girl with a Mandolin (Fanny Tellier)","oil on canvas",1910,edytta)
edytta.sell_artwork(girl_with_mandolin, "$6M (USD)")
veneer.show_listings()
moma.buy_artwork(girl_with_mandolin)
print(girl_with_mandolin)
veneer.show_listings()