有一个程序请教一下各位
计算机从下面的单词表["python","game","food","easy","number","integer"]中随机抽取一个单词(例如:game),随机打乱字母顺序后(例如打乱成emga)展示给玩家,让玩家去猜是哪个单词。玩家猜错,给出提示“不对,请重猜”;玩家猜对,给出提示“恭喜,猜对了!
继续吗?(Y/N)",玩家输入“Y”或“y”继续,输入“N”或“n”退出。
编写python背单词程序
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
溪风沐雪 2022-05-01 19:03关注给个例子,仅供参考:
import random WORDS = ["python","game","food","easy","number","integer"] while True: if len(WORDS)==0: print('恭喜,全猜完了') break word = random.choice(WORDS) cur_word = word a = '' for i in word: postion = random.randrange(len(word)) a += word[postion] word = word[0:postion] + word[(postion+1):] print("乱序后的单词:", a) guess = input("输入你的猜测:") while guess!=cur_word: guess = input("不对,请重猜:") s = input('恭喜,猜对了!继续吗?(Y/N)') if s=='Y' or s=='y': WORDS.remove(cur_word) continue else: break
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报