Hey Guys! Hope your having a great time!
I just finished the VENEER task including the additional tasks in 35. I’m coding for three weeks now and I would really appreciate it, if someone could review my code and give me some feedback (especially concerning legibility and maybe some ways to use less lines of code).
Thank you so much!
`this import is needed for the last extra task###
import datetime
###no questions, everything works fine###
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 f"{self.artist}. \"{self.title}\". {self.year}, {self.medium}. {self.owner.name}, {self.owner.location}."
###Do you have suggestions to make the expiration_date task more handy integrated?
###I dont feel like my appending to show_listings is the best way...
class Marketplace:
def __init__(self, listings):
self.listings = []
def add_listing(self, new_listing):
self.listings.append(new_listing)
def remove_listing(self, to_be_removed_listing):
self.listings.remove(to_be_removed_listing)
def show_listings(self):
for listing in self.listings:
if listing.expiration_date <= datetime.datetime.now():
veneer.remove_listing(listing)
else:
print(listing)
veneer = Marketplace([])
###Also here I'm happy for any suggestions to make my code more readable and especially shorter.###
class Client:
def __init__(self, name, location, is_museum, wallet):
self.name = name
self.wallet = wallet
self.wishlist =[]
if location == False:
self.location = "Private Collection"
else:
self.location = location
if is_museum == False:
self.is_museum = "It is not a museum."
if is_museum == True:
self.is_museum = "Museum"
def __repr__(self):
return f"The name is {self.name}, the art is in the location {self.location}. {self.is_museum}. The person owns {self.wallet}.\nwishlist: {self.wishlist}"
def sell_artwork(self, artwork, price, expiration_date):
if artwork.owner == self:
veneer.add_listing(Listing(artwork, price, self,expiration_date))
self.wallet += price
def buy_artwork(self, artwork, price):
art_listing = None
if artwork.owner != self:
for listing in veneer.listings:
if listing.art == artwork:
art_listing = listing
artwork.owner = self
veneer.remove_listing(art_listing)
self.wallet -= price
def add_to_wishlist(self, artwork):
for listing in veneer.listings:
if listing.art == artwork:
self.wishlist.append(listing)
class Listing:
def __init__(self, art, price, seller, expiration_date):
self.art = art
self.price = price
self.seller = seller
self.expiration_date = expiration_date
def __repr__(self):
return f"The name of this piece of art is \"{self.art.title}\". The price is {self.price}. The offer is valid until {self.expiration_date}."
edytta = Client("Edytta Halprit", False, False, 0)
moma = Client("The MOMA", "New York", True, 6000000)
girl_with_mandolin = Art("Picasso, Pablo", "Girl with a Mandolin (Fanny Tellier)", "oil in canvas", 1910, edytta)
###You can modify the expiration date. If you call show_listings and the expiration date is after the datetime.datetime.now(), it will be deleted from the list.
edytta.sell_artwork(girl_with_mandolin, 6000000, datetime.datetime(2020,12,24))
#moma.buy_artwork(girl_with_mandolin, 6000000)
veneer.show_listings()
#print(girl_with_mandolin)
###Thanks for reviewing! I'm happy for any feedback!`