[Tutor] Loops and User Input
Glen Wheeler
wheelege@tsn.cc
Sat, 3 Mar 2001 08:32:39 +1100
This is a multi-part message in MIME format.
------=_NextPart_000_00B1_01C0A3BC.81E4AB80
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Your script works fine on my system. I suggest trying it out through =
the command prompt, or using the Activestate version of the python =
interpreter. I used to use IDLE but it seems to have alot of issues (at =
least the version for MS Windows does).
The easiest way to run a script through the command prompt (if you =
haven't set the path to point at your python20 directory) is to first =
copy that script to the python20 directory. Then open up a DOS prompt, =
and change directories to the c:\python20 directory. It is probably =
different if youa re using a different version of python...but since I =
started when python 2 was realeased I have no idea what the directory =
name would be for previous versions :)
You change directories by typing "dir <dirname>" without the quotes, =
where <dirname> is python20 in this case.
Then just type "python <scriptname>" to run the script. Don't forget =
the .py at the end of the filename :)
Cya,
Glen.
----- Original Message -----=20
From: Marty Pitts=20
To: tutor@python.org=20
Sent: Saturday, March 03, 2001 6:52 AM
Subject: [Tutor] Loops and User Input
I'm a python newbie and I have been going through Mr. Gauld's book and =
have a question.
=20
Following an exercise to understand loops, the following came about:
=20
for i in range(2, 13):
for j in range(1, 13):
if i =3D=3D 2 and j =3D=3D 1:
print "---------------------------------- "
print "This table is the",i,"multiple table"
print "---------------------------------- "
print "%d x %d =3D %d" % (j, i, j * i)
if i =3D=3D 12:
break
print "---------------------------------- "
print "This table is the",i + 1 ,"multiple table"
print "---------------------------------- "
=20
Which works fine.
=20
However, when I add user input to let the range be dependant on this =
input like this:
=20
multiplier =3D input("Which mulitplier value do you want to use? ")
for i in range(2, multiplier + 1):
for j in range(1, multiplier + 1):
if i =3D=3D 2 and j =3D=3D 1:
print "---------------------------------- "
print "This table is the",i,"multiple table"
print "---------------------------------- "
print "%d x %d =3D %d" % (j, i, j * i)
if i =3D=3D multiplier:
break
print "---------------------------------- "
print "This table is the",i + 1 ,"multiple table"
print "---------------------------------- "
=20
Using any input just returns to a prompt in 'idle'.
=20
Any help will be appreciated.
=20
Thanks,
------=_NextPart_000_00B1_01C0A3BC.81E4AB80
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 content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV> </DIV>
<DIV> Your script works fine on my system. I suggest trying =
it out=20
through the command prompt, or using the Activestate version of the =
python=20
interpreter. I used to use IDLE but it seems to have alot of =
issues (at=20
least the version for MS Windows does).</DIV>
<DIV> The easiest way to run a script through the command prompt =
(if you=20
haven't set the path to point at your python20 directory) is to first =
copy that=20
script to the python20 directory. Then open up a DOS prompt, and =
change=20
directories to the c:\python20 directory. It is probably different =
if youa=20
re using a different version of python...but since I started when python =
2 was=20
realeased I have no idea what the directory name would be for previous =
versions=20
:)</DIV>
<DIV> You change directories by typing "dir <dirname>" =
without the=20
quotes, where <dirname> is python20 in this case.</DIV>
<DIV> Then just type "python <scriptname>" to run the =
script. =20
Don't forget the .py at the end of the filename :)</DIV>
<DIV> </DIV>
<DIV> Cya,</DIV>
<DIV> Glen.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV=20
style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
<A href=3D"mailto:marty55@home.com" title=3Dmarty55@home.com>Marty =
Pitts</A>=20
</DIV>
<DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:tutor@python.org"=20
title=3Dtutor@python.org>tutor@python.org</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Saturday, March 03, 2001 =
6:52=20
AM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] Loops and User =
Input</DIV>
<DIV><BR></DIV>
<DIV><FONT face=3DArial size=3D2>I'm a python newbie and I =
have been=20
going through Mr. Gauld's book and have a question.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Following an exercise to understand =
loops, the=20
following came about:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>for i in range(2, =
13):<BR> for=20
j in range(1, 13):<BR> if i =
=3D=3D 2 and j =3D=3D=20
1:<BR> print=20
"---------------------------------- "<BR> =
=20
print "This table is the",i,"multiple=20
table"<BR> =
print=20
"---------------------------------- "<BR> =
=20
print "%d x %d =3D %d" % (j, i, j * i)<BR> if i =
=3D=3D=20
12:<BR> =
break<BR> print=20
"---------------------------------- "<BR> print =
"This table=20
is the",i + 1 ,"multiple table"<BR> print=20
"---------------------------------- "</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Which works fine.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>However, when I add user input to let =
the range=20
be dependant on this input like this:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>multiplier =3D input("Which =
mulitplier value do you=20
want to use? ")<BR>for i in range(2, multiplier + =
1):<BR> =20
for j in range(1, multiplier + 1):<BR> =
if=20
i =3D=3D 2 and j =3D=3D 1:<BR> =
=20
print "---------------------------------- "<BR> =20
print "This table is =
the",i,"multiple=20
table"<BR> =
print=20
"---------------------------------- "<BR> =
=20
print "%d x %d =3D %d" % (j, i, j * i)<BR> if i =
=3D=3D=20
multiplier:<BR> =20
break<BR> print "----------------------------------=20
"<BR> print "This table is the",i + 1 ,"multiple=20
table"<BR> print "---------------------------------- =
"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Using any input just returns to a =
prompt in=20
'idle'.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Any help will be =
appreciated.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2>Thanks,</FONT></DIV></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_00B1_01C0A3BC.81E4AB80--