After changing a variable, the next input that's supposed to use the updated variable uses the old one

Viewed 38

I'm very new to python and Stack overflow so sorry if my question is lacking information, but I hope you can solve it.

To give some background, I am making a game that generates a random alphabet with some words in there (kind of like a word search) and I am unable to remove a specific letter (to make it easier for the user to guess) until after the response has been given. Valid words are the words that are in the alphabet, and random_az_word is a string of a random alphabet.

Here is the code:

while not user_win:
user_input = input(input_question)
if user_input in valid_words:
    user_win = True
while not user_input.isalpha():
    user_valid = False
    input_question = 'Please put in a valid word '
    user_input = input(input_question)
if user_input not in valid_words:
    while not remove:
        remove_num = random.randint(1,int(len(random_az_word)-1))
        if random_az_word[remove_num] not in ''.join(valid_words):
            remove = True
    random_az_word = random_az_word.replace(random_az_word[remove_num],'')
    input_question = f'Incorrect, please try again, after removing the letter {random_az_word[remove_num]} alphabet is {random_az_word} '

After wards, the input question ends up with the old alphabet (without the removed letter), until after you put in a response.

PS. I'm very tired right now so I could just be missing a very noticeable mistake, I apologize if that's the case.

0 Answers
Related