# Guess the word game
import random #Add to
WORDS =("python","juice","easy","difficult","answer","continue","phone","hello","pose","game")print("Welcome to the word guessing game\n Combine letters into a correct word")
iscontinue ="Y"while iscontinue=="Y" or iscontinue=="Y": #cycle
# Pick a word randomly from the sequence
word = random.choice(WORDS)
# A variable that determines whether the player guessed correctly
correct = word
# Create out-of-order words
jumble =""print(word)while word: #word is not an empty string
# According to word length, generate random position of word
position = random.randrange(len(word))
# Combine position letters into out-of-order words
jumble+=word[position]
# By slicing, delete the position letter from the original word
word = word[:position]+word[(position+1):]print("Words after disorder:",jumble)
guess =input("\nPlease guess:")while guess != correct and guess !="":print("Sorry. Incorrect")
guess =input("Keep guessing")if guess == correct:print("Awesome, you guessed it")
iscontinue =input("\n whether to continue (Y/N):") #Whether to continue the game
Just learn that Python does not have a semicolon. Its indentation is to judge the logical continuous position. Pay attention to the indentation, otherwise an error will occur.
Recommended Posts