Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMo Reese
11,868 PointsOOP DreamVacation Challenge
Error says: Bummer: NameError: name 'DreamVacation' is not defined, but this was already provided by the challenge.
Instructions: Below is a class called DreamVacation that holds a location and list of activities. Create a @classmethod called rome that will return a new DreamVacation instance with cls() with the following arguments: location = 'Rome' and activities list = ['visit the Colosseum', 'Eat gelato'].
Hint: The classmethod should take cls instead of self as an argument.
Help is appreciated!
class DreamVacation:
def __init__(self, location, activities):
self.location = location
self.activities = activities
@classmethod
def rome(cls):
itenerary = []
itenerary.append(DreamVacation("Rome", "visit the Colosseum", "Eat gelato"))
return cls(itenerary)
1 Answer
Buster Siem
7,280 PointsHi, You only need to return the cls-argument in the body of the class method (I don't know where you got the whole itenerary-function from):
itenerary = []
itenerary.append(DreamVacation("Rome", "visit the Colosseum", "Eat gelato"))
return cls(itenerary)
Nonetheless, this needs to be removed.
You should then just call return of your argument, cls, and give it a string that matches the location and the activities-list parameters:
@classmethod
def rome(cls):
return cls('Rome', ['visit the Colosseum', 'Eat gelato'])
Mo Reese
11,868 PointsMo Reese
11,868 PointsYeah, I thought that I needed an empty list in order to place the location & activities... Wish I could say that was the first or last time that I would over-think my answer... Thanks for your help!