Jump to content
Sign in to follow this  

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:

   time.sleep(2)
        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]:
                time.sleep(2)
                print "congratulations!!! "
                traverse(question, answers, index)
            else:
                tries = tries - 1
                print "wrong answer you have", tries, "attempts left"
        print "Arividechi"
        exit()

 

codeaquiz.py

Share this post


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. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×