[Tutor] Please critique my Fraq.py (original) (raw)

Brian van den Broek bvande at po-box.mcgill.ca
Sun Jul 25 11:44:02 CEST 2004


Dick Moores said unto the world upon 25/07/2004 05:29:

I've had various responses to my request for a critique of my Frac.py (I mispelled it as Fraq.py in the subject header--must have had Iraq on my mind.)

Before I begin to try to implement your valuable suggestions for Frac.py, I'd like to try again for a response to a specific question I asked in that post: In Frac.py I wanted to give the user a chance to quit at any prompt (and have the program close smoothly), by entering a "q" or an "x". I did this by the statement, if answer in ["q", "x"]: break The problem with this is that it only breaks out of the inner loop. I have to repeat this statement in the outer loop. So I'm asking if there's a better way. Raising an exception doesn't do it. Is there a way (other than mine) to enable the user to quit smoothly when he's inside a loop which is inside a loop? Here's a silly game/test script I wrote to try to illustrate my question: """ print "This is an appropriate response test." print "Enter q or x to give up." while True: while True: answer = rawinput("How are you today: ") if answer == "x": print "Give up? O.K., you can try again tomorrow." break elif answer != "Fine, thank you. And you?": print "C'mon. That's dumb. Try again." continue else: print "Congratulations! You passed the test!" break break "" At two points in the inner loop I've got a break. But I need another at the end of the outer loop to get out smoothly. Thanks, Dick Moores

Hi Dick,

I haven't followed your thread closely so I don't recall your program. Thus, it might not meet your definition of "smooth" in the case at hand, but have you tried sys.exit() ?

Best,

Brian vdB



More information about the Tutor mailing list