计算机随机产生一个单词,打乱字母顺序,供玩家去猜
'''
import random
#创建单词序列
WORDS = ("python","jumble","easy","difficult","answer","continue","phone","position","pose","game")
print(
"""
欢迎参加猜单词小游戏
请把字母组合成一个正确的单词
""")
iscontinue = "y"
while iscontinue == "y" or iscontinue == "Y":
word = random.choice(WORDS)
correct = word
jumble = "" #创建乱序后的单词
while word: #当word不是空串室循环
position = random.randrange(len(word))
jumble += word[position] #将Position位置的字母组合到乱序后的单词
word = word[:position] + word[(position+1):] #通过切片将Position位置的字母从原单词中删除
print("乱序后单词:",jumble)
guess = input("\n请你猜:")
while guess!=correct and guess!="":
print("对不起不正确")
guess = input("继续猜:")
if guess == correct:
print("真棒,你猜对了!")
iscontinue = input("\n是否继续(Y/N):")
'''