[Tutor] Help using Random module

antonmuhin at rambler.ru antonmuhin at rambler.ru" <antonmuhin@rambler.ru
Thu Apr 17 13:08:12 2003

Hello Danny,

Thursday, April 17, 2003, 1:13:36 AM, you wrote:

D> Hi Everyone,

D> My question is, I want to use the random module to pick a random number from 1,100 I read up on it but am very confused about how to use it properly. What I've tried to say is. 

D> def number(x):
D>     x = random.randrange(1,100)
D>     result = x
D>     return result
D> guess = 0

D> while guess != number:
D>     guess = input ("guess a number")

D>     if guess > number:
D>         print "Too High"
D>         print guess

D>     elif guess < number:
D>         print "too Low"
D>         print guess

D> print "Just Right"

D> When I run the program the random number is always greater then 100 what am I doing wrong? Also what does it mean when the module has a uppercase letter. For example random.Random is that the same
D> as random.random?? Thanks for everyone help.

D> Danny D

Several bugs slipped into your code:

1. number and number() are quite different and you meant number() .
2. Actually it seems that you meant something like this:

current_number = number()

and number->current_number

Otherwise you'll get new random number each time you call number

Best regards,
 anton                            mailto:antonmuhin@rambler.ru