'override variable declared inside class

I want to override variable which is declared inside of a class Bank, as you can see in the code below, I've tow inits, chosen_word and word, the first one, is declared when calling the function, the second one word is declared inside of a function, what I want to do is to override that word but python returns an error saying : TypeError: __init__() missing 1 required positional argument: 'word'

class Bank:
    def __init__(self,chosen_word,word):
        self.chosen_word = chosen_word
        self.word = word
    
    def choose_theme(self):
        if chosen_word == "World":
            word = random.choice(math)
            splitten_word = split(word)
            elements = ['_'.format(element) for element in splitten_word]
            print(elements)
        elif chosen_word == "Hello":
            word = random.choice(tech)
            splitten_word = split(word)
            elements = ['_'.format(element) for element in splitten_word]
            print(elements)
chosen_word = input("choose word:" + str(temebi))
levani = Bank(chosen_word)
levani.choose_theme()


Solution 1:[1]

Your constructur demands for two parameters chosen_word and word

def __init__(self,chosen_word,word):

Here you are not providing word

levani = Bank(chosen_word)

That's the error message. You need to provide this argument or modify your constructor p.e.:

def __init__(self,chosen_word, word=None):
  if word == None:
    self.chosen_word = chosen_word
    self.word = chosen_word
  else:
    self.chosen_word = chosen_word
    self.word = word

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 miro