Python basic "guess the word game" code

""" 
Program function: Werd Jumble word guessing game 
Writer: Sun Sansui 
Date of writing: 2022/9/10 
""" 
import random 

# Create word sequence 
WORDS = ( 
    "python", "jumble", "easy", " difficult", "answer", 
    "continue", "phon", "position", "result", "game" 
) 
# start the game 
print( 
    """ 
       Welcome to the word guessing game, 
    combine the letters into a correct word 
    " "" 
) 
iscontinue = "y" 
while iscontinue == "y" or iscontinue == "Y": 
    # Randomly pick a word from the program 
    word = random.choice(WORDS) 
    # A variable used to judge whether the player guesses correctly 
    correct = word 
    # Create random words 
    jumble = ""  
    while word: # Loop when word is not an empty string
        # According to the length of the word, generate a random position of the word
        position = random.randrange(len(word)) 
        # delete the position letter from the original word 
        jumble += word[position] 
        # delete the position position letter from the original word by slicing 
        word = word[:position] + word[ (position + 1):] 
        print("\n\n Words after random order:", jumble) 
        guess = input("Please guess:") 
        while guess != correct and guess != "": 
            print("Sorry Incorrect") 
            guess = input("Please continue to guess:") 
        if guess == correct: 
            print("Awesome, you guessed it right!") 
            iscontinue = input("Whether to continue (Y/N):")

Guess you like

Origin blog.csdn.net/Sjm05/article/details/126792802