猜单词游戏。计算机在单词库中随机产生一个单词,打乱字母顺序,供玩家猜。
单词库参考:"python", "game", "int", "float", "complex", "string", "list", "tuple", "dict", "set"
import random
words = ["python", "game", "int", "float", "complex", "string", "list", "tuple", "dict", "set"]
#随机选择一个单词
selected_word = random.choice(words)
#打乱单词字母顺序
shuffled_word = ''.join(random.sample(selected_word,len(selected_word)))
# 打印打乱后的单词
print("打乱后的单词:", shuffled_word)
print("请猜猜这个单词是:")
# 玩家猜测单词
while(True):
guess = input()
# 检查玩家的猜测是否正确
if guess == selected_word:
print("恭喜!你猜对了!")
break
else:
print("很遗憾,你猜错了。")
print("请接着往下猜:")
