简体   繁体   English

如何在Mad Libs游戏中更改号码?

[英]How to change number in Mad Libs game?

I'm trying to create a Mad Libs-style game in which there is a time limit of 1 minute. 我正在尝试创建一个疯狂的Libs风格的游戏,其中时间限制为1分钟。 Once the time limit is reached, the game ends and "GAME OVER" is displayed. 一旦达到时间限制,游戏就会结束并显示“ GAME OVER”。 If the user finishes within the time limit, the results are displayed. 如果用户在时限内完成操作,则显示结果。 I'm using a while loop and time.time() so that the first question is asked, the while loop repeats, the second question is asked, the while loop repeats, etc. But I can't figure out how to change the question number as the game progresses so that when the while loop finishes with one question, it moves on to the next. 我正在使用while循环和time.time(),以便询问第一个问题,重复while循环,询问第二个问题,while循环重复,等等。但是我不知道如何更改问题编号随着游戏的进行而变化,以便当while循环结束一个问题时,它将继续进行下一个问题。

start = time.time()
    questionNum = 1

    question1 = "Enter the name of a male acquaintance: "
    question2 = "Enter the name of a place: "
    question3 = "Enter an adverb: "
    question4 = "Enter a verb: "
    question5 = "Enter a plural noun: "
    question6 = "Enter a verb: "
    question7 = "Enter the vocation of a person: "
    question8 = "Enter a verb ending with -ing: "
    question9 = "Enter an emotion (past tense): "
    question10 = "Enter a grade letter: "
    question11 = "Enter a school subject: "
    question12 = "Enter the meaning of the letter grade A: "
    question13 = "Enter the meaning of the letter grade B: "
    question14 = "Enter the meaning of the letter grade C: "
    question15 = "Enter the meaning of the letter grade D: "
    question16 = "Enter the meaning of the letter grade E: "
    question17 = "Enter the meaning of the letter grade F: "
    question18 = "Enter an aggressive verb: "

    while time.time() - start < 60:
        answer1 = input(question1)
        questionNum +=1
    else:
        print("Too bad, slowpoke. GAME OVER!")

You might want to have them in a list of some sort: 您可能希望将它们放在某种列表中:

questions = [ "Enter the name of a male acquaintance: ",
  "Enter the name of a place: ",
  ... ]

then you'll collect answers in a list too: 那么您也会在列表中收集答案:

answers = []
while time.time() - start < 60:
    answers.append(input(questions[questionNum]))
    questionNum +=1

You can then check if user have answered all the questions by comparing lengths of question and answer lists: 然后,您可以通过比较问题和答案列表的长度来检查用户是否已回答所有问题:

if len(answers) < len(questions):
    print("Too bad, slowpoke. GAME OVER!")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM