-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path034Marketplace.py
76 lines (57 loc) · 2.09 KB
/
034Marketplace.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
74
75
# Marketplace for people and organizations
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}. {owner_name}, {owner_location}""".format(artist = self.artist,title = self.title, medium = self.medium, year = self.year, owner_name = self.owner.name, owner_location = self.owner.location)
class Marketplace:
def __init__(self):
self.listings = []
def add_listing(self, new_listing):
self.listings.append(new_listing)
def remove_listing(self, deleted_listing):
self.listings.remove(deleted_listing)
def show_listings(self):
for listing in self.listings:
print(listing)
veneer = Marketplace()
veneer.show_listings()
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 artwork.owner == self:
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)
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)
print(girl_with_mandolin)
class Listing:
def __init__(self, art, price, seller):
self.art = art
self.price = price
self.seller = seller
def __repr__(self):
return "{name}, {price}".format(name = self.art.title, price = self.price)
edytta.sell_artwork(girl_with_mandolin, "$6M (USD)")
veneer.show_listings()
moma.buy_artwork(girl_with_mandolin)
print(girl_with_mandolin)
veneer.show_listings()