------------------------------------------------------------------------- def print_options(): print "------------------------------" print "Options:" print "a. print options" print "f. quit the programme" print "------------------------------"
print_options() choice = 0 while choice != 'f': print choice = raw_input("Choose an option: ") if choice == 'a': print "Here we go again" print_options() if choice == 'f': break
print_options()
-------------------------------------------------------------------------
Is it that if you use "while 1:" you create a recursive function? Hope I am right.
Thanks JC
-------------------------------------------------------------------------------------------- PREVIOUS EMAIL
OK the situation is that I haven't still found out what the answer is, I
have noticed in the other hand that if I select the option "a" let'ssay 4
times, I need to enter the option "f" 4 times. I am curious to knowwhat the
solution is. I have read your chapter on recursion but that did notclear
anything.
OK, basically the problem is that you have unintentionally created a recursive function. Every time you call it you create a new copy of the function. When you exit the function you wind up back in the previous copy. So as many times as you call the function you have to exit it the same number of times to get back to the top of your program.
Have a think about it, and see if that makes sense.
Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor