[Chicago] pedantic guessing game demo

Brian Ray brianhray at gmail.com
Sat Mar 26 22:40:28 CET 2011


Fun... One comment on:

*    print "I'm thinking of a number between 1 - 100.  Can you guess
what it is?"
>
>     random_num = random.randint(1, 100)
>
>     guess = int(input("Type a number between 1 - 100: "))
>
>
>     error = guess < 1, guess < 100
>
> *
>
> I think that error was put in there so you can handle errors correct, one
way to add some error handing there is add something like:

    while True:

        guess = int(input("Type a number between 1 - 100: "))
        if guess < 1 or guess  > 100:
            print "%s out of range try again" % guess
            continue

        break


 - Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20110326/dcf96e0d/attachment.html>


More information about the Chicago mailing list