The example in this article shares the specific code of python to realize the word guessing game for your reference. The specific content is as follows
# 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.
More interesting classic mini game implementation topics, share with you:
C++ classic games summary
Python classic games summary
python tetris game collection
JavaScript classic games are constantly playing
JavaScript classic games summary
The above is the whole content of this article, I hope it will be helpful to everyone's study.
Recommended Posts