Jump to content

Recommended Posts

Hello folks. I am currently learning Python programming. I have created a fill in the blanks quiz game. In this game, the user has to select a level hard, medium, easy. On the basis of teh level selected, the respective question and its answers are passed as parameters into the function, question validation, this function takes user input and sees whether is matches the question and answer input. If it does, then the answer is passed onto the function, traverse. At traverse, the blanks are filled in and the sentence is returned with missing blank filled in. This seems to work well upto filling in the fourth blank. At this stage if I get the answer wrong on the first attempt and I later answer correctly, it then prompts me to fill in the 4th again. Its acting like an infinite loop. I cant for the life of me seem to solve this!!!!

The problem lies here:

        print "wrong answer you have", tries, " attempts left"
        while tries>0:
            print "Fill in ",blanks[index], " please"
            response = raw_input()
            response = response.upper()
            if response == answers[index]:
                print "congratulations!!! "
                traverse(question, answers, index)
                tries = tries - 1
                print "wrong answer you have", tries, "attempts left"
        print "Arividechi"



Link to post
Share on other sites

You haven't told the loop to end when the user gives a correct answer.  The 'tries' variable is still greater than zero so the loop continues. 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...