break the loop in one object and then return

Alex Pavluck apavluck at gmail.com
Mon Jun 26 19:44:20 CEST 2006


I am trying to write the following code to block up evaluation and
prompting for entering new information.  However, when I break the loop
in one object and then return it does not start at the beginning again
but rather at the point where it exited.  Can someone look at the
following code and give me some feedback.





yournum = input("I am thinking of a number between 1 and 100.\n  Guess
which number: ")
mynum = (yournum-5)

def eval():
    if yournum == mynum:
        print "Wow!  You got it!"
    elif yournum < mynum:
        print "Nope.  Too low"
        again()
    elif yournum > mynum:
        print "Oh, your too high"
        again()

def again():
    global yournum
    yournum = input("guess again: ")
    eval()

eval()




More information about the Python-list mailing list