What's wrong with this code?

Sébastien Boisgérault Sebastien.Boisgerault at gmail.com
Sat Jul 2 13:47:06 EDT 2005



Nathan Pinno a écrit :
> Hi all,
>
>   What's wrong with the following code? It says there is name error, that
> random is not defined. How do I fix it?

Add "import random" at the top of your file

Cheers,

SB

>   # Plays the guessing game higher or lower.
>   # Originally written by Josh Cogliati, improved first by Quique, then by
> Nathan Pinno.
>   print "Higher or Lower"
>   print
>   number = random.choice(range(100))
>   guess = 0
>   while guess != number:
>       guess = input("Guess a number: ")
>       if guess > number:
>           print "Too high"
>           guess = input("Guess a number: ")
>       elif guess < number:
>           print "Too low"
>           guess = input("Guess a number: ")
>   print "Just right"
>
>   Thanks.
>   Nathan Pinno
>   http://www.npinnowebsite.ca/
>
>
>
> --
>
>
> ----------------------------------------------------------------
>      Posted via UsenetRevolution.com - Revolutionary Usenet
> ** HIGH RETENTION ** Specializing in Large Binaries Downloads **
>                  http://www.UsenetRevolution.com




More information about the Python-list mailing list