Python简单猜单词游戏

import random
lists = [“house”, “hello”, “world”, “please”]
flag = 0
count = 1
word = random.choice(lists) #从列表里随机选取一个单词
#print(“原单词为:”,word)
reword = list(word)
random.shuffle(reword) #将选出的单词字母随机排序
print(“顺序错乱的单词:”, “”.join(reword)) #将reword里面所有的元素合并成一个新的字符串

guess = input(“请输入猜测的单词:”)
while flag == 0:
if guess == word:
flag = 1
print(“猜测正确!”)
else:
count += 1
guess=input(“猜测错误!请重试:”)
if count == 10:
print(“您已猜错10次,正确的单词为:”, word)
flag=0
break
if flag == 1:
print(“正确率为:”, round(1/count*100, 1), “%”)

你可能感兴趣的:(Python)