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

Ahmed Ali
Ahmed Ali
Courses Plus Student 2,923 Points

AttributeError: 'Game' object has no attribute 'used_locations'

Not understanding this error, my code looks identical to the one in the video

from cards import Card
import random

class Game():
    def __init__(self):
        self.size = 4
        self.card_options = ['Add', 'Boo', 'Cat', 'Dev', 'Egg', 'Far', 'Gum', 'Hut']
        self.columns = ['A', 'B', 'C', 'D']
        self.cards = []
        self.locations = []
        for column in self.columns:
            for num in range(1, self.size + 1):

    def set_cards(self):
        used_locations = []
        for word in self.card_options:
            for i in range(2):
                avaliable_locations = set(self.locations) - set(self.used_locations)
                random_location = random.choice(list(avaliable_locations))
                card = Card(word, random_location)

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

1 Answer

Steven Parker
Steven Parker
215,940 Points

Perhaps it's not quite "identical".   :see_no_evil:

This code has "self. used_locations" where the video just has "used_locations".

Ahmed Ali
Ahmed Ali
Courses Plus Student 2,923 Points

🤦🏾‍♂️ Well that was a good lesson to learn. Ty