[Tutor] Re Help with this script
Alan Gauld
alan.gauld at freenet.co.uk
Mon Apr 25 20:08:34 CEST 2005
> can't see it really, i thought that the fact to have the "break"
command
> would terminate the script straight away.
break terminates the current loop, which is inside your print_options
function. print_options is called from inside print_options.
Research the term "recursion" and see if you can see where the problem
lies.
(Try my online tutor for one explanation...)
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
If I enter "f" first then the
> programme ends. What am i missing?
>
> JC
>
> John Carmona wrote:
>
> Thanks for the help Kent, Noel and Alan. Here is my final script (it
> seems to be working ok but sometimes if I select "quit the
programme", I
> need to enter that option 2 or 3 times before it works, is this a
bug
>
>
> Try this program. Choose option a a few times, then choose f enough
times to
> exit. See if you can figure out what is going on.
>
> def print_options():
> print "------------------------------"
> print "Options:"
> print "a. print options"
> print "f. quit the programme"
> print "------------------------------"
> while 1:
> choice = raw_input("Choose an option: ")
> if choice == 'a':
> print 'About to call print_options'
> print_options()
> print 'Finished calling print_options'
> if choice == 'f': break
>
> print_options()
>
> Kent
>
>
>
>
More information about the Tutor
mailing list