python实现猜单词小游戏
**思路
1.首先使用列表自己构建一个单词库WORDS,然后使用random中的choice从中随机抽取一个单词。
2.然后用while循环语句每次随机抽入一个字符放入乱序的newword字符串中,并将原word中删除字符。
3.最后输出两种可能即可。
代码块:
猜单词
import random
WORDS = ("python","jumple","easy","difficult","answer","continue","phone","position","game")
iscontinue = "y"
while iscontinue == "y" or iscontinue == "Y":
words = random.choice(WORDS)
right = words
newwords = ""
while words:
position = random.randrange(len(words))
newwords += words[position]
words = words[:position] + words[(position + 1):]
print("扰乱后的单词",newwords)
guess = input("\n请你猜单词")
# if guess == words:
# print("恭喜你,猜对了")
# else:
# print("抱歉,你猜错了")
while guess != right and guess != "":
print("抱歉,你猜错了")
guess = input("\n请你继续猜单词")
if guess == right:
print("恭喜你,猜对了")
iscontinue = input("\n\n是否继续(Y/N):")
**运行图:**
![在这里插入图片描述](https://img-blog.csdnimg.cn/9c344f5efdf2480e93a038d66d95b4d1.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5peg5aKo772e57Sg5rWK,size_18,color_FFFFFF,t_70,g_se,x_16)