#导入random模块
import random
#给WORDS设置几个单词组成元组
WORDS=("python","jumble","easy","password","answer","iPhone")
#从元组中随机获取一个单词传递给word
word=random.choice(WORDS)
#word元组传递参数给correct
correct=word
#创建一个空的变量jumble
jumble=""
#开始把word 单词顺序打乱并输出,循环
while word:
#随机获取word参数下标
position = random.randrange(len(word))
#通过下标找到对应数据传递给jumble变量
jumble += word[position]
#word变量去除上面的随机数据后组成的新的变量
word = word[:position]+word[(position+1):]
#输出变量jumble的具体数据
print("The jumble is:",jumble)
#获取人为输入的数据
guess=input("\n your guess:")
#输入数据和抽选的数据做比较
#是否不同或为空
while guess!=correct and guess !="":
#输出提示
print("Sorry, that's not it.'")
#提示不对后,重新输入
guess = input("your guess:")
#输入跟抽选数据相同,提示正确
if guess==correct:
print("that's it! you guessed it!\n")
#enter键结束进程
input("\n\npress the enter key to exit.")
领取专属 10元无门槛券
私享最新 技术干货