[Tutor] Program not accessing while loops
Glen Wheeler
wheelege@tsn.cc
Tue, 1 May 2001 19:12:18 +1000
This is a multi-part message in MIME format.
------=_NextPart_000_0100_01C0D272.A3F1A040
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<snip snip snip>
mainmen =3D raw_input(">")
while mainmen =3D=3D 1:
<snip snip snip>
Your getting a string here, and not an integer. So, 'while mainmen =
=3D=3D 1' will never, ever be true. Ever.
So, what you want is to convert it to an integer...with something like =
:-
mainmen =3D int(raw_input(">"))
To account for something other than an integer, and to make sure it =
doesn't crash when the user writes something like 'go away!', wrap it in =
a try-except block.
try:
mainmen =3D int(raw_input(">"))
except:
print 'Please enter an integer'
Hope that helped,
Glen.
------=_NextPart_000_0100_01C0D272.A3F1A040
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 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><snip snip snip><BR><FONT face=3DArial =
size=3D2> =20
mainmen =3D raw_input(">")<BR> while mainmen =3D=3D =
1:</FONT><BR><snip snip snip></DIV>
<DIV> </DIV>
<DIV> Your getting a string here, and not an integer. So, =
'while=20
mainmen =3D=3D 1' will never, ever be true. Ever.</DIV>
<DIV> So, what you want is to convert it to an integer...with =
something=20
like :-</DIV>
<DIV> </DIV>
<DIV> mainmen =3D int(raw_input(">"))</DIV>
<DIV> </DIV>
<DIV> To account for something other than an integer, and to make =
sure it=20
doesn't crash when the user writes something like 'go away!', wrap it in =
a=20
try-except block.</DIV>
<DIV> </DIV>
<DIV> try:</DIV>
<DIV> mainmen =3D =
int(raw_input(">"))</DIV>
<DIV> except:</DIV>
<DIV> print 'Please enter an =
integer'</DIV>
<DIV> </DIV>
<DIV> Hope that helped,</DIV>
<DIV> Glen.</DIV></BODY></HTML>
------=_NextPart_000_0100_01C0D272.A3F1A040--