This is the link for the veneer python code:
The code
when I hit run it gives me an Error. Can someone please tell me how to fix it.
Hello, @elhussein800, and welcome to the Codecademy Forums!
Link to project page: Veneer
In your buy_artwork
method of Client
, you have this within the if
block in the for
loop:
item = art_listing
What is the purpose of that statement?
Sorry I don’t remember. I guess it made since when I wrote it.
Here is what you have for the buy_artwork
method:
def buy_artwork(self, artwork):
if artwork.owner != self:
art_listing = None
for item in veneer.listings:
if item.art == artwork:
item = art_listing
veneer.remove_listing(art_listing)
Prior to the for
loop, the code initializes art_listing
to None
. Within the loop, you look for artwork
in veneer.listings
, using item
to represent each element in veneer.listings
. If it is found, this statement gets executed:
item = art_listing
Since you previously initialized art_listing
to None
, that statement assigns None
to item
. Then here you are inadvertently attempting to remove None
from the listings:
veneer.remove_listing(art_listing)
Instead of this …
item = art_listing
… you need to save the found item to art_listing
, like this:
art_listing = item
After that you will still need to change the transfer the art to the new owner.
Thanks so much. That really helped.
The last out come should say
Monet, Claude. “Vétheuil in the Fog”. 1879, oil on canvas. The MOMA, New York.
but instead it says
Picasso, Pablo. “Girl with a Mandolin (Fanny Tellier)”. 1910, oil on canvas. Edytta Halpirt, Private Collection.
how can I fix that?
Hi @elhussein800,
We need to see the most recent version of your code. Please post it, so that we can help. To make sure the code is formatted correctly in your post, see How to ask good questions (and get good answers) for advice.
This is my most recent code. Sorry, I’m new here. I’m sure I will get used to it.
### Veneer ## The Thin Veneer of Viability 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 "{a}. \"{b}\". {c}, {d}. {e}, {f}.".format(a = self.artist, b = self.title, c = self.year, d = self.medium, e = self.owner.name, f = self.owner.location) ## The Marketplace of Artistic Ideas class Marketplace: def __init__(self): self.listings = [] def add_listing(self, new_listing): self.listings.append(new_listing) def remove_listing(self, old_listing): self.listings.remove(old_listing) def show_listings(self): for item in self.listings: print(item) veneer = Marketplace() veneer.show_listings() ## We Need Clients! class Client: def __init__(self, name, location, is_museum): self.name = name self.is_museum = is_museum if is_museum: self.location = location else: self.location = "Private Collection" def sell_artwork(self, artwork, price): if artwork.owner == self: new_listing = Listings(artwork, price, self) veneer.add_listing(new_listing) def buy_artwork(self, artwork): if artwork.owner != self: art_listing = None for item in veneer.listings: if item.art == artwork: art_listing = item 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) ## Don't Be Listless class Listings: def __init__(self, art, price, seller): self.art = art self.price = price self.seller = seller def __repr__(self): return "{a}, ${b}".format(a = self.art, b = self.price) edytta.sell_artwork(girl_with_mandolin, 6) veneer.show_listings() moma.buy_artwork(girl_with_mandolin) print(girl_with_mandolin) veneer.show_listings()
See instruction 31. The buy_artwork
method of Client
needs to transfer the art to the new owner, but your does has not implemented that yet. Consult the video, if necessary.
If any problem occurs, please post your code for that method.