2D游戏开发课程第2次作业

主宰稳场 提交于 2020-03-08 17:13:11

一、序列应用——猜单词游戏

代码

import random
WORDS=("apple","banana","cat","dog","elephant","finger","grand","hello","illness")
print("欢迎参加猜单词游戏,把字母组合成一个正确的单词")
iscontinue="y"
while iscontinue=="y" or iscontinue=="Y":
    word=random.choice(WORDS)
    correct=word
    jumble=""
    while word:
        position=random.randrange(len(word))
        jumble+=word[position]
        word=word[:position]+word[(position+1):]
    print("乱序后单词:",jumble)
    guess=input("\n请你猜:")
    while guess !=correct and guess !="":
        print("对不起不正确")
        guess=input("继续猜:")
    if guess==correct:
        print("真棒,你猜对了!\n")
    iscontinue = input("\n\n是否继续(Y/N):")
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!