[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>&nbsp;</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.&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>def number(x):<BR>&nbsp;&nbsp;&nbsp; x =
=3D=20
random.randrange(1,100)<BR>&nbsp;&nbsp;&nbsp; result =3D =
x<BR>&nbsp;&nbsp;&nbsp;=20
return result<BR>&nbsp;&nbsp;&nbsp; <BR>guess =3D 0</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>while guess !=3D =
number:<BR>&nbsp;&nbsp;&nbsp; guess=20
=3D input ("guess a number")</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; if guess &gt;=20
number:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "Too=20
High"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print =
guess</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; elif guess &lt;=20
number:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "too=20
Low"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print =
guess</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>print "Just Right"<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Danny D</DIV></FONT></BODY></HTML>

------=_NextPart_000_0021_01C3042A.C0B63510--