[Tutor] Now what do I do?(was Re: When I run this code, it just keeps repeating.)

Alan G alan.gauld at freenet.co.uk
Sun Jul 31 10:11:46 CEST 2005

> while cal_opt != 9:
>    menu()
>    cal_opt = cal()
>    if cal_opt == 1:
>    elif cal_opt == 2:
>    elif cal_opt == 7:
>    else:
>        print "That's not an option. Try again."
>        menu()
>        cal()

Because you don't have a specific check for the exit value (9) the 
else part gets executed which asks the user for another value.
If you put in a test for 9 that does nothing (ie use 'pass') 
then the while loop will fail on its next attempt and the 
program will stop. 

Other options inclde using 'break' to break out of the loop when 
cal_opt == 9 or using 'continue' to force the while loop to start 


Alan G
Author of the Learn to Program web tutor

More information about the Tutor mailing list