[Tutor] Help using Random module
Danny
wheelcrdan@hotmail.com
Thu Apr 17 10:33:02 2003
This is a multi-part message in MIME format.
------=_NextPart_000_0021_01C3042A.C0B63510
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi Everyone,
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.=20
def number(x):
x =3D random.randrange(1,100)
result =3D x
return result
=20
guess =3D 0
while guess !=3D number:
guess =3D input ("guess a number")
if guess > number:
print "Too High"
print guess
elif guess < number:
print "too Low"
print guess
print "Just Right"
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 as random.random?? =
Thanks for everyone help.
Danny D
------=_NextPart_000_0021_01C3042A.C0B63510
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1141" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi Everyone,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>My question is, I want to use the =
random module to=20
pick a random number from 1,100 I read up on it but am very confused =
about how=20
to use it properly. What I've tried to say is. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>def number(x):<BR> x =
=3D=20
random.randrange(1,100)<BR> result =3D =
x<BR> =20
return result<BR> <BR>guess =3D 0</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>while guess !=3D =
number:<BR> guess=20
=3D input ("guess a number")</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> if guess >=20
number:<BR> print "Too=20
High"<BR> print =
guess</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> elif guess <=20
number:<BR> print "too=20
Low"<BR> print =
guess</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>print "Just Right"<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>When I run the program the random =
number is always=20
greater then 100 what am I doing wrong? Also what does it mean when the =
module=20
has a uppercase letter. For example random.Random is that the same as=20
random.random?? Thanks for everyone help.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Danny D</DIV></FONT></BODY></HTML>
------=_NextPart_000_0021_01C3042A.C0B63510--