Python,逐渐减少尝试

时间:2016-07-09 23:46:10

标签: python-2.7

我是Python的初学者,我一直收到这个错误:

  

TypeError:' NoneType'对象不可迭代

我想要做的是先获得此测验,然后问你想要尝试的时间并获得正确的答案,然后在达到倒计时之后停止。任何帮助或输入将不胜感激。我也试图弄清楚如何填写像这样的空白

fill_in_blanks = ["__1__", "__2__", "__3__", "__4__", "__5__"]

这是我的代码

fill_in_blanks = ["__1__", "__2__", "__3__", "__4__", "__5__"]

# Question and answer for each level of play
easy_level = "The answers will consist of female or male. My sister is a __1__. My father " \
         "is a __2__. My mother is a __3__.  My grandmother is a __4__.  " \
         "My grandfather is a __5__."
easy_answers = ["female", "male", "female", "female", "male"]       #allowing the user to select the level of play
        def select_level():
            print "\nPlease choose a level. You can choose easy, medium, hard, or     bonus"
            choice = raw_input("Enter your level now: ")
            return choice


def select_attempt():
    attempt = raw_input("Please chose the number of your attempts 1 to 5. ")
    return attempt


def countdown(attempt):
     while attempt > 0:
        attempt = attempt - 1
        return attempt


# getting the correct level quiz and answers
def get_quiz(level):
    if level=="easy":
        return (easy_level, easy_answers)
    if level=="medium":
        return (medium_level, medium_answers)
    if level=="hard":
        return (hard_level, hard_answers)
    if level=="bonus":
        return (bonus_level, bonus_answers)


# checking the users answers vs the levels answers
def play_game(questions, answers, attempt, fill_in_blanks):
    while attempt > 0:
        print questions
        for i in range(0, 5):
           user_input = raw_input("\n Please type the answer for blank " + str(i+1) + ".")
            print "user input is " + user_input
            print "the answer is " + answers[i]
            if user_input == answers[i]:
                i += i + 1
                print ("Awesome!")
                print questions
            if user_input != answers[i]:
                attempt = attempt - 1
                user_input = raw_input("\n Oops! Incorrect! Please type the answer for blank " + str(i+1) + ".")
            return "Have a great day!"

# play game
def start_game():
    level = select_level()
    attempt = select_attempt()
    answers, questions = get_quiz(level)
    play_game(answers, questions, attempt, fill_in_blanks)


start_game()

0 个答案:

没有答案