w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Python - Why are the words not randomly generating after each round in my Word jumble game?

Because you are choosing the random selection outside of the while loop. Move that part of your code to the beginning of the while loop and it should choose a new selection every time the game starts over.

while word:
    word = random.choice(WORDS)
    position = random.randrange(len(word))
    jumble += word[position]
    word = word[:position] + word[(position + 1):]

You are going to need to change the condition of the while loop since word won't exist yet when it checks for it. Something like while playing and have playing be a bool that you can set to false so you can end the loop for whatever reason.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.