[Tutor] Loops and User Input
Marty Pitts
marty55@home.com
Fri, 2 Mar 2001 20:47:47 -0800
This is a multi-part message in MIME format.
------=_NextPart_000_000B_01C0A35A.09BF73E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Much to my embarrassment, this script works for me if I run it at the =
command prompt and not in idle.
Though my primary platform is linux and not windows. =20
I don't know why I did not try it as a script. I assumed that if it =
didn't work in idle, it wouldn't work any other way.
Thanks for the comments.
----- Original Message -----=20
From: Glen Wheeler=20
To: Marty Pitts=20
Cc: tutor@python.org=20
Sent: Friday, March 02, 2001 1:32 PM
Subject: Re: [Tutor] Loops and User Input
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.
Following an exercise to understand loops, the following came about:
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 "---------------------------------- "
Which works fine.
However, when I add user input to let the range be dependant on this =
input like this:
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 "---------------------------------- "
Using any input just returns to a prompt in 'idle'.
Any help will be appreciated.
Thanks,
------=_NextPart_000_000B_01C0A35A.09BF73E0
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.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Much to my embarrassment, this script =
works for me=20
if I run it at the command prompt and not in idle.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Though my primary platform is linux and =
not=20
windows. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I don't know why I did not try it as a=20
script. I assumed that if it didn't work in idle, it wouldn't work =
any=20
other way.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks for the comments.</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-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 title=3Dwheelege@tsn.cc href=3D"mailto:wheelege@tsn.cc">Glen =
Wheeler</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dmarty55@home.com =
href=3D"mailto:marty55@home.com">Marty Pitts</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>Cc:</B> <A title=3Dtutor@python.org =
href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, March 02, 2001 =
1:32=20
PM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: [Tutor] Loops and =
User=20
Input</DIV>
<DIV><BR></DIV>
<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=20
that script to the python20 directory. Then open up a DOS =
prompt, and=20
change directories to the c:\python20 directory. It is probably=20
different if youa re using a different version of python...but since I =
started=20
when python 2 was realeased I have no idea what the directory name =
would be=20
for previous versions :)</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=20
script. 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"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-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 title=3Dmarty55@home.com href=3D"mailto:marty55@home.com">Marty =
Pitts</A>=20
</DIV>
<DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dtutor@python.org=20
href=3D"mailto:tutor@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=20
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> =20
for j in range(1, 13):<BR> if i =
=3D=3D 2=20
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 *=20
i)<BR> if i =3D=3D 12:<BR> =20
break<BR> print=20
"---------------------------------- "<BR> print =
"This=20
table 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=20
you want to use? ")<BR>for i in range(2, multiplier +=20
1):<BR> for j in range(1, multiplier +=20
1):<BR> if i =3D=3D 2 and j =
=3D=3D=20
1:<BR> 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 *=20
i)<BR> if i =3D=3D =
multiplier:<BR> =20
break<BR> print=20
"---------------------------------- "<BR> print =
"This=20
table 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>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=20
size=3D2>Thanks,</FONT></DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_000B_01C0A35A.09BF73E0--