Как я могу использовать атрибут word_store в другой функции того же класса AttributeError: объект 'Hangman' не имеет атрибута 'word_store' - PullRequest
0 голосов
/ 06 мая 2020
class Hangman:  #class hangman
    def Word_list(self):
        result=random.choice(['debtee', 'mob', 'freight', 'torment', 'freight train', 'boredom','botcher', 'bothersome', 'bungler', 'continuation', 'officially', 'practically']) 
        word_len=len(result)
        word_store=list(result)     

    def main_game(self):
        #print('The word is %s long'%Word_list.list_result_len)
        spaces=[]
        for space in range(1,10):

            spaces.append('_ ')
            chance=10
        print(spaces)   
        for x in range(1,10):


            choose =input('Kindly choose a letter that you think this word contains :')
            if choose in self.word_store:     #facing the issue here
                position=self.word_store.index(choose)
                spaces[position]= choose
                print(spaces)
                print("Great!! This letter is present in the word, Keep Going")

            else:
                chance=chance-1
                print("Sorry this letter does not exist in the word")
                hangman_figure(chance)

1 Ответ

0 голосов
/ 08 мая 2020

Вы должны использовать self. во всех функциях для создания и использования переменной класса

  self.word_store = list(result)
...