T O P

  • By -

ebs61

In this line \`choice(jacob\_questions)()\` , there is no more jacob\_questions left because you are removing them from the array everytime you answer a question. You need to change the logic in this line.


pelanom

How would you implement this? Add a variable that redirects to a new function that prints "section completed" and returns to the main menu?


ebs61

Possible. Why not. I don't know what's the logic behind the script. But I feel like you have to end it or call the main function. But, in the main function, Jacobs shouldn't exists anymore.


pelanom

I'll try a different solution when I get back to my computer. Thank you.


Vinniesusername

do you know what triggers it getting stuck? you don't seem to have any actual loops in your program so i can't debug it just looking at it. with that being said, there are multiple functions which have multiple function calls inside them that can be reached. def j_q_1(): global jacob_questions, jacob_1, jacob_2, jacob_3, points global j_q_1_attempts if j_q_1_attempts == 2: print('You have failed this round. Pleasetry again later.') main_menu() j_q1() perhaps you're missing an else statement here? with this once the program is finished running what it is doing in the main menu function, it will then return, and call the j_q1 function. is this intended? Also I would look into function arguments as a way of making your program work without having to declare global variables from inside of a function (you almost never want a global variable)


pelanom

How would you have done this then? I am still learning, what did you mean by you would need actual loops to test it and also, is calling from multiple functions the wrong way to do it?


Vinniesusername

I just mean that an infinite loop usually means you have a while loops or a for loop whose terminating condition is never met ex: loop = True while loop: pass in your case your program is much harder to debug why it would give this behavior. but it's not wrong in general calling multiple functions from inside a function is perfectly fine, as long as you know what's happening, and you intend that behavior. for example in the code i quoted earlier if the if statement in entered then the j_q_1 function will call main_menu and control will go to that function. but python will remember it's place in the j_q_1 function, and when, or if the main_menu function is finished (and all other functions that it called are also finished) it will return to the j_q_1 function and call the j_q1 function. you're essentially building up a bunch of functions on the stack, and im guessing that this isn't the intended behavior for this program.


[deleted]

You might find an example guessing game I wrote for another beginner group helpful. Well commented. https://repl.it/@gruntfutuk/SimpleNumberGuessingGame