Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python填空游戏给出错误答案_Python - Fatal编程技术网

Python填空游戏给出错误答案

Python填空游戏给出错误答案,python,Python,因此,我对python和一般编程都是新手。作为练习,我正在试着填补空白。我想出了这个程序,但由于某种原因,每当我回答第二个问题时,我总是出错。它继续说答案是错误的,即使这是正确的答案。对于我如何纠正这个问题/如何使代码更好,我将不胜感激。提前感谢您的帮助。您为什么一直在添加用户输入用户输入+=原始输入(?)我的印象是,为了回答不同的问题,我必须这样做。将变量分配给新的原始输入,以检查其是否等于答案[]。不要添加用户输入;替换它。在这种情况下,只需删除+。 easy_game = 'Hello

因此,我对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()