Python填写空白游戏给出错误的答案

时间:2016-03-05 21:13:11

标签: python

 easy_game = 'Hello welcome to my game \n Lets start off with some easy     questions about the Python programming language. \n This is a placeholder     that allows to attach a name to something __1__. \n A __2__ uses \"\" or \'\' to allow the program to know what it is. \n When using the + sign you do this __3__ to variables. __4__ are symbols that are used to calculate or assign values to variables. '
easy_answers = [ 'variables',
             'string',
             'concatenate',
             'operators' ]

medium_game = 'Hello welcome to my game \n Lets start off with some   medium questions about the Python programming language. A __1__ operator allows you to divide a numeric value and return the remainder. When there is an error in your program the way you fix it is to \n __2__ your program. \n This is the error you will recieve if you misspell or forget soemthing that \n makes it impossible for the program to compile : __3__ error \n There are different types of these but they all iterate through your program : __4__'
medium_answers = [ 'modulus',
               'debug',
               'syntax',
               'loops']

 hard_game = 'Hello welcome to my game \n Lets start off with some hard questions about the Python Programing language. \n This type of loop will continue to run as long as it is true: __1__ \n When using a comparison this is used to say not equal to : __2__ \n Creating a __3__ also creates certain methods inside it. When creating a \n function you may have to pass something into the parentheses. \n This is called passing in an : __4__. '
hard_answers = ['while',
            '!=',
            'class',
            'argument']

def select_difficulty():
     print "\n Please choose a difficulty. The three options you can    choose from are \n Easy , Medium, Hard"
     choice = raw_input().lower()
     return choice

def get_q_a(difficulty):
    if difficulty=="easy":
        return (easy_game, easy_answers)
    if difficulty=="medium":
        return (medium_game,medium_answers)
    if difficulty=="hard":
        return (hard_game,hard_answers)

def play_game(questions,answers):
    print questions
    user_input = raw_input("\n Please answer the questions in Order")
    if user_input == answers[0]:
        questions = questions.replace('__1__', answers[0])
    if user_input != answers[0]:
        user_input = raw_input("\n Incorrect Please answer the questions in Order")
    print questions
    user_input += raw_input("\n Please answer second question")
    if user_input == answers[1]:
        questions += questions.replace('__2__', answers[1])
    if user_input != answers[1]:
        user_input = raw_input("\n Incorrect Please answer the questions again")
    print questions
    user_input += raw_input("\n Please answer the Third question ")
    if user_input == answers[2]:
        questions += questions.replace('__3__', answers[2])
    if user_input != answers[3]:
        user_input = raw_input("\n Incorrect Please answer the questions again")
    print questions
    user_input += raw_input("\n Please answer the fourth question")
    if user_input == answers[3]:
       questions += questions.replace('__4__', answers[3])
       print "congradulations"
    if user_input != answers[3]:
       user_input = raw_input("\n Incorrect Please answer the question again")





def start_game():
    difficulty = select_difficulty()
    answers , questions = get_q_a(difficulty)
    play_game(answers, questions)

start_game()

所以我是python和编程的新手。我试图填补空白游戏作为练习。我想出了这个程序,但由于某种原因,我一直在回答第二个问题时遇到错误。它继续说答案是不正确的,即使它是正确的答案。任何帮助将非常感谢我如何纠正这个/如何使代码更好。提前感谢您的帮助。

0 个答案:

没有答案