-5

I am currently doing Udacity's introduction to programming development course. As a part of this course, I have to create a fill in the blanks game. The game is structured like this:

The user is asked to choose a level based on difficulty. Once the user decides what level he/she wants to play, the parameters: question, the answers to that question, blanks list, and an index of 0 are passed to the function Question Validation.

At the question validation function. We assess whether user input matches what is contained in the answers based on the index. For example, if I am filling in the first blank, then my answer(input) must equal that of answers[0]. If it does not then the user has 4 tries to get it right. If the user does not, the game is quit. Once the user selects the right answer, this is passed to the function traverse.

Here is the code for question validation

https://www.dropbox.com/sh/e5doud7wt2awlfo/AACoMdohawZj54RwjIWvtAKda?dl=0

The function traverse takes in as parameters:the question; the list of answers to that question; and the index as parameters. Based on this information, this function will fill in the question blanks accordingly and passes this back to the question validation for the user to then fill in the next blank. When all the blanks are filled, the program is stopped.

Here is the code for traverse

https://www.dropbox.com/s/w4cra1hah5xww9q/traversefunct.py?dl=0

I have written comments in my code that further elaborate on what I have outlined here.

Here is the complete code

https://www.dropbox.com/s/npendg2ey63e8rr/codeaquiz.py?dl=0

The code seems to work fine and does what I want it to do up until filling the 4th blank. At this point if I choose the wrong answer and then go back and choose the right answer. It acknowledges that I have chosen the right answer but then prompts for the answer again. Its an infinite loop and I cant see for the life of why it is happening here when for filling in previous blanks it was not working.

Here is a screenshot of what is happening with regards to being prompted again:

https://www.dropbox.com/s/s8sk8r19gz4ued2/Screenshot%202018-04-27%2014.13.22.png?dl=0

I cant for the life of me see why:

  • 6
    Please include a [mcve] **in the question itself**. Questions should be self-contained; we shouldn't have to go off-site to figure out what your question is. – EJoshuaS - Stand with Ukraine Apr 27 '18 at 13:59
  • Welcome to Stack Overflow! I suggest that you read https://ericlippert.com/2014/03/05/how-to-debug-small-programs/ for tips on how to debug your own code. Debugging is one of the most important skills for you to learn as an aspiring programmer. Also take a few minutes to read [ask] and [mcve] for tips on improving your question here on SO. – Code-Apprentice Apr 27 '18 at 14:00
  • 1
    You never `break` your while loop in the else statement. – zipa Apr 27 '18 at 14:17
  • 2
    [I downvoted because being unresponsive to comments is not helpful](http://idownvotedbecau.se/beingunresponsive). – EJoshuaS - Stand with Ukraine Apr 27 '18 at 16:45

1 Answers1

0

As zipa pointed out, you never break your while loop in the else statement on line 146 unless you run out of tries. A one line "fix" is to simply put an exit() after line 98 within the traverse() function.

natn2323
  • 1,983
  • 1
  • 13
  • 30
  • what could I do to improve the way I composed the question? – bobby midha Apr 27 '18 at 15:55
  • (Probably) try to follow the rules that the other users posted. In addition, present a question that is succinct and as limited in scope as possible. For instance, "I can't see for the life of me why [my program isn't functioning correctly]" is not a good question, if it even is a question. Unfortunately, although you did provide all the necessary info to come to a solution, the scope of the problem was too large; debug your program as far as you can, then ask the question about whatever remains that needs explaining. Also, rather than explaining the program here, comment it in your code! :) – natn2323 Apr 27 '18 at 16:53
  • If my response helped to solve your problem / answer your question, please select it as the Accepted Answer! – natn2323 Apr 27 '18 at 16:54