Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Basic Object-Oriented Python Creating a Memory Game Game Class Part 1

Ava Jones
Ava Jones
2,663 Points

line 19 used_locations.append(random_location) Syntax Error

from cards import Card
import random
class Game:
  def __init__(self):
    self.size = 4
    self.card_options = ["Goat", "Maid", "Toad", "Tape", "Hill", "Farm", "Frog", "Girl"]
    self.columns = ["A", "B", "C", "D"]
    self.cards = []
    self.locations = []
    for column in self.columns:
      for num in range(1, self.size + 1):
        print(f'{column}{num}')
  def set_cards(self):
    used_locations = []
    for word in self.card_options:
      for i in range(2):
        available_locations = set(self.locations) - set(self.used_locations)
        random_location = random.choice(list(available_locations)
        used_locations.append(random_location)
        card = Card(word, random_location)
        self.cards.append(card)


if __name__ == '__main__':
  game = Game()
  game.set_cards()
  for card in game.cards:
    print(card)

[MOD: added ```python formatting -cf]

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,064 Points

Hey Ava Jones , there is a simple typo: a missing close paren on the previous line 18.

Post back if you need more help. Good luck!!!

Ava Jones
Ava Jones
2,663 Points

Now it is saying that Game has no attribute used_locations

Chris Freeman
Chris Freeman
Treehouse Moderator 68,064 Points

Hi! In the assignment to available_locations there is a reference to the non-existing attribute self.used_locations. I think you meant the local variable used_locations (without the self. prefix)

Ava Jones
Ava Jones
2,663 Points

I am getting an error saying available_locations = set(self.locations) - set(self.used_locations) again game has no attribute used_locations

Ava Jones
Ava Jones
2,663 Points

and my if __name__ == '__main__' is glowing red but only the if is glowing

Chris Freeman
Chris Freeman
Treehouse Moderator 68,064 Points

One change at a time. Change

# change
available_locations = set(self.locations) - set(self.used_locations)

# to
available_locations = set(self.locations) - set(used_locations)
Ava Jones
Ava Jones
2,663 Points

Never mind I will just start over thank you though