[Tutor] Program not accessing while loops
alan.gauld@bt.com
alan.gauld@bt.com
Tue, 1 May 2001 10:36:09 +0100
------_=_NextPart_001_01C0D222.26EA8A80
Content-type: text/plain; charset="iso-8859-1"
keep running and asking for input, but it won't call on the loop.
mainmen = raw_input(">")
while mainmen == 1:
raw_input returns a string, you are testing for a number.
You need to convert mainmen to an int:
mainmen= int(mainmen)
OR you need to test for a string:
while mainmen n== "1"
BUT do you really want a while loop here?
It will loop forever printing
print "This function is under construction"
Surely an if statement would be sufficient?
Specifically an if/elif set:
if mainmenu == 1: print...
elif mainmenu == 2: print...
elif mainmenu == 3:
# do the exit stuff here
just a thought,
Alan G.
------_=_NextPart_001_01C0D222.26EA8A80
Content-type: text/html; charset="iso-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 5.00.3013.2600" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<BLOCKQUOTE
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
<DIV><FONT face=Arial size=2>keep running and asking for input, but it won't
call on the loop.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> mainmen =
raw_input(">")<BR> while mainmen == 1:<BR><SPAN
class=970153809-01052001><FONT
color=#0000ff> </FONT></SPAN></FONT></DIV></BLOCKQUOTE>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=970153809-01052001>raw_input returns a string, you are testing for a
number. </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970153809-01052001>You
need to convert mainmen to an int:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=970153809-01052001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=970153809-01052001>mainmen= int(mainmen)</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=970153809-01052001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970153809-01052001>OR you
need to test for a string:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=970153809-01052001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970153809-01052001>while
mainmen n== "1"</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=970153809-01052001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970153809-01052001>BUT do
you really want a while loop here?</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970153809-01052001>It
will loop forever printing </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=970153809-01052001></SPAN></FONT> </DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
<DIV><FONT size=2><FONT face=Arial><SPAN
class=970153809-01052001> </SPAN>
print "This function is under construction"</FONT></FONT></DIV></BLOCKQUOTE>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN
class=970153809-01052001>Surely an if statement would be
sufficient?</SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN
class=970153809-01052001></SPAN></FONT></FONT> </DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN
class=970153809-01052001>Specifically an if/elif set:</SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN
class=970153809-01052001></SPAN></FONT></FONT> </DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN
class=970153809-01052001>if mainmenu == 1: print...</SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN
class=970153809-01052001>elif mainmenu == 2: print...</SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN
class=970153809-01052001>elif mainmenu == 3: </SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN
class=970153809-01052001> # do the exit stuff
here</SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN
class=970153809-01052001></SPAN></FONT></FONT> </DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN
class=970153809-01052001>just a thought,</SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN
class=970153809-01052001></SPAN></FONT></FONT> </DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN
class=970153809-01052001>Alan G.</SPAN></FONT></FONT></DIV></BODY></HTML>
------_=_NextPart_001_01C0D222.26EA8A80--