-
-
Save codecademydev/eb365f3a9e62831f8d1983d3c947332d to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
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): | |
self.repr = '{artist}. "{title}". {year}, {medium}. {owner}, {location}.'.format(artist=self.artist,title=self.title,medium=self.medium,year=self.year,owner=self.owner.name,location=self.owner.location) | |
return self.repr | |
class Marketplace: | |
def __init__(self): | |
self.listings = [] | |
def add_listing(self,new_listing): | |
self.listings.append(new_listing) | |
def remove_listing(self,listing): | |
self.listings.pop(self.listings.index(listing)) | |
def show_listings(self): | |
print(self.listings) | |
class Client: | |
def __init__(self,name,location,museum,funds): | |
self.name = name | |
self.location = location | |
self.is_museum = museum | |
self.wallet = funds | |
def sell_artwork(self,artwork,price,expiration): | |
if artwork.owner == self: | |
listing = Listing(artwork,price,self,expiration) | |
veneer.add_listing(listing) | |
def buy_artwork(self,artwork): | |
if artwork.owner != self: | |
for listing in veneer.listings: | |
if artwork == listing.art and listing.price <= self.wallet: | |
art_listing = artwork | |
artwork.owner = self | |
veneer.remove_listing(listing) | |
self.wallet = self.wallet - listing.price | |
listing.seller.wallet += listing.price | |
if artwork.title in self.wishlist: | |
self.wishlist.remove(artwork.title) | |
elif listing.price > self.wallet: | |
print("Insufficient funds.") | |
def add_to_wishlist(self,artwork): | |
self.wishlist = [] | |
if artwork.owner != self: | |
for listing in veneer.listings: | |
if artwork == listing.art: | |
self.wishlist.append(artwork.title) | |
class Listing: | |
def __init__(self,art,price,seller,expiration): | |
self.art = art | |
self.price = price | |
self.seller = seller | |
self.expiration = datetime.datetime.strptime(expiration,'%Y-%m-%d') | |
def __repr__(self): | |
self.repr = '{title}: {price}'.format(title=self.art.title,price=self.price) | |
return self.repr | |
veneer = Marketplace() | |
print(veneer.show_listings()) | |
edytta = Client("Edytta Halpirt", "Private Collection", False, 1000000) | |
moma = Client("The MOMA", "New York", True, 10000000) | |
girl_with_mandolin = Art("Picasso, Pablo", "Girl with a Mandolin (Fanny Tellier)", 1910, "oil on canvas", edytta) | |
art2 = Art("Me", "Great Art", 2020, "digital", edytta) | |
print(girl_with_mandolin) | |
edytta.sell_artwork(girl_with_mandolin, 6000000, '2020-12-31') | |
edytta.sell_artwork(art2, 20000000, '2020-12-31') | |
veneer.show_listings() | |
moma.add_to_wishlist(girl_with_mandolin) | |
moma.add_to_wishlist(art2) | |
print(moma.wishlist) | |
moma.buy_artwork(girl_with_mandolin) | |
print(girl_with_mandolin) | |
veneer.show_listings() | |
moma.buy_artwork(art2) | |
print(edytta.wallet) | |
print(moma.wallet) | |
print(moma.wishlist) | |
while True: | |
for listing in veneer.listings: | |
if listing.expiration > datetime.datetime.now(): | |
veneer.remove_listing(listing) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment