[Tutor] NEWBIE QUEASTION ALERT - how to restart program?
Ole Jensen
ole_jensen@dbmail.dk
Fri Dec 20 19:28:02 2002
This is a multi-part message in MIME format.
------=_NextPart_000_0051_01C2A890.0C6AD480
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Alright, as the subject says - Im not the most educated man in python =
(or any other language), but I been going through some tutorials.=20
And as I have expanded the trials in order not to just copy and paste I =
was wondering how it is possible to go back in the script/file in order =
to restart certain section in order for the program not just to shut =
down... well e.g.:
This program has been modified from the area calculator found in the =
instant hacking tutorial =
http://www.hetland.org/python/instant-hacking.php
_________________________________________________________________________=
__
# Area calculator
print "WELCOME TO THE AREA CALCULATOR"
print "------------------------------"
print ""
print ""
# Import the sleep mode in order to display results before shut down
from time import sleep
# meny
print "Select a shape"
print "1: Quadrangle"
print "2: Circle"
shape =3D input(">>>")
if shape =3D=3D 1:
print "Is it a:"
print ""
print "1: square"
print "2: rectangle"
quad_shape =3D input(">>>")
if quad_shape =3D=3D 1:
print "Square"
S =3D input("What is the lenght of any side?")
print ""
print "The area is",S**2
sleep(5)
elif quad_shape=3D=3D 2:
print "rectangle"
L =3D input("What is the lenght?")
W =3D input("What is the width?")
print ""
if L =3D=3D W:
print "this not a rectangle!"
sleep(5)
else:
print "The area is",L*W
sleep(5)
else:
print "wrong key!!!"
sleep(5)
elif shape =3D=3D 2:
print "circle"
R =3D input("What is the radius?")
print ""
print "The area of the circle is:",R**2*3.14
sleep(5)
=20
else:
print "Grow up man... 1 or 2!!!"
sleep(5)
_________________________________________________________________
If you run this program independently the window will close automaticly =
after it has been run, now instead of just closing the window how would =
it be possiple to re-run the program, e.g. in the first many you have a =
choice of: 1 or 2. if the user presses any other key, the program will =
print "grow up man... 1 or 2!!!" and shut down/close the window (given =
after waiting 5 seconds), now instead I would like the program to ask =
the question again... how is that done...?
given it maight not be crutial, but I really would like to know how its =
done. and finally I should say I have no understanding of how the loops =
work (I've gone through tutorials about the FOR-loops and WHILE-loops =
but they make no sense to me) so if loops are esantial to what i want to =
achive I was wondering if any of you reading this could guide me to some =
very basic walk-through's of loops
thanx for listing and for any help you provide!
sincerly Ole Jensen
PS this mail is been resent due to I got replay to my old mail reading =
something like this: "Policy =3D Dirty Words" this was properbly because =
the program code contained certain words that some people might not =
like.... the word has been removed an I am hoping the mail will go =
through now...
------=_NextPart_000_0051_01C2A890.0C6AD480
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.1126" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Alright, as the subject says - Im not =
the most=20
educated man in python (or any other language), but I been going through =
some=20
tutorials. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>And as I have expanded the trials in =
order not to=20
just copy and paste I was wondering how it is possible to go back in the =
script/file in order to restart certain section in order for the program =
not=20
just to shut down... well e.g.:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>This program has been modified from the =
area=20
calculator found in the instant hacking tutorial <A=20
href=3D"http://www.hetland.org/python/instant-hacking.php">http://www.het=
land.org/python/instant-hacking.php</A></FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>________________________________________________________________=
___________</FONT></DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
<DIV><FONT face=3DArial size=3D2># Area calculator<BR>print "WELCOME =
TO THE AREA=20
CALCULATOR"<BR>print "------------------------------"<BR>print =
""<BR>print=20
""</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2># Import the sleep mode in order to =
display=20
results before shut down<BR>from time import sleep</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2># meny<BR>print "Select a =
shape"<BR>print "1:=20
Quadrangle"<BR>print "2: Circle"<BR>shape =3D =
input(">>>")</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>if shape =3D=3D =
1:<BR> print "Is it=20
a:"<BR> print ""<BR> print "1:=20
square"<BR> print "2: =
rectangle"<BR> =20
quad_shape =3D input(">>>")</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> if quad_shape =
=3D=3D=20
1:<BR> print=20
"Square"<BR> S =3D =
input("What is the=20
lenght of any side?")<BR> =
print=20
""<BR> print "The area=20
is",S**2<BR> =
sleep(5)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> elif =
quad_shape=3D=3D=20
2:<BR> print=20
"rectangle"<BR> L =3D =
input("What is=20
the lenght?")<BR> W =3D =
input("What is=20
the width?")<BR> print=20
""<BR> if L =3D=3D=20
=
W:<BR> =
print=20
"this not a=20
=
rectangle!"<BR> &nbs=
p; =20
sleep(5)<BR> =20
=
else:<BR> &nbs=
p;=20
print "The area=20
=
is",L*W<BR> &n=
bsp;=20
sleep(5)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> =20
else:<BR> print "wrong=20
key!!!"<BR> =
sleep(5)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>elif shape =3D=3D =
2:<BR> print=20
"circle"<BR> R =3D input("What is the=20
radius?")<BR> print ""<BR> print =
"The area=20
of the circle is:",R**2*3.14<BR> =20
sleep(5)<BR> <BR>else:<BR> print =
"Grow up=20
man... 1 or 2!!!"<BR> =
sleep(5)</FONT></DIV></BLOCKQUOTE>
<DIV dir=3Dltr><FONT face=3DArial=20
size=3D2>________________________________________________________________=
_</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>If you run this program =
independently the=20
window will close automaticly after it has been run, now instead of just =
closing=20
the window how would it be possiple to re-run the program, e.g. in the =
first=20
many you have a choice of: 1 or 2. if the user presses any other key, =
the=20
program will print "grow up man... 1 or 2!!!" and shut down/close the =
window=20
(given after waiting 5 seconds), now instead I would like the program to =
ask the=20
question again... how is that done...?</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>given it maight not be =
crutial, but I=20
really would like to know how its done. and finally I should say I have =
no=20
understanding of how the loops work (I've gone through tutorials about =
the=20
FOR-loops and WHILE-loops but they make no sense to me) so if loops are =
esantial=20
to what i want to achive I was wondering if any of you reading this =
could guide=20
me to some very basic walk-through's of loops</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>thanx for listing and for any =
help you=20
provide!</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>sincerly Ole =
Jensen</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>PS this mail is been =
resent due to I=20
got replay to my old mail reading something like this: <FONT=20
face=3D"Times New Roman" size=3D3>"Policy =3D Dirty Words" this was =
properbly because=20
the program code contained certain words that some people might not =
like.... the=20
word has been removed an I am hoping the mail will go through=20
now...</FONT></FONT></DIV></BODY></HTML>
------=_NextPart_000_0051_01C2A890.0C6AD480--