import random ? ? ?#随机函数 words =("conscietious","noteworthy") i = random.randint(0,len(words)-1) ? ? ? ? ?#随机单词的下标 b = list(words[i]) ? ? ? ? ? ?#将单词(字符串)转换成列表 random.shuffle(b) ? ? ? ? ? #打乱字符列表的顺序 for j in range(len(b)): ?? ?print("{} ".format(b[j]),end='') ?? ?if j + 1 >= len(b): ?? ??? ?print() a = input("Please input the word : ") while a != ' ': ?? ?if a == words[i]: ?? ??? ?print('Congratulation!\nGuess right!the word is "{}"'.format(words[i])) ?? ??? ?c = input("Do you want continue guess words?\ny:yes;n:no\nPlease choose: ") ?? ??? ?print() ?? ??? ?if c == "y" or c == "yes" : ?? ??? ??? ?i = random.randint(0,len(words)-1) ?? ??? ??? ?b = list(words[i]) ?? ??? ??? ?random.shuffle(b) ?? ??? ??? ?for j in range(len(b)): ?? ??? ??? ??? ?print("{} ".format(b[j]),end='') ?? ??? ??? ?if j + 1 >= len(b): ?? ??? ??? ??? ?print() ?? ??? ??? ?a = input("Please input the word : ") ?? ??? ??? ?continue ?#返回循环头,继续下一轮循环 ?? ??? ?elif c == 'n' or c == ' ' or c == 'no': ?? ??? ??? ?break #退出循环 ?? ?else: ?? ??? ?print("Sorry,Guess wrong!") ?? ??? ?c = input("Do you want to continue?\n y:yes;n:no\nPlease choose: ") ?? ??? ?if c == 'y' or c == "yes" : ?? ??? ??? ?print() ?? ??? ??? ?i = random.randint(0,len(words)-1) ?? ??? ??? ?b = list(words[i]) ?? ??? ??? ?random.shuffle(b) ?? ??? ??? ?for j in range(len(b)): ?? ??? ??? ??? ?print("{} ".format(b[j]),end='') ?? ??? ??? ?if j + 1 >= len(b): ?? ??? ??? ??? ?print() ?? ??? ??? ?a = input("Please input the word : ") ?? ??? ??? ?continue ?#返回循环头,继续下一轮循环 ?? ??? ?elif c == 'n' or c == ' ': ?? ??? ??? ?break ? #退出循环
|