[Tutor] (no subject)
melvin2001
melvin2001@earthlink.net
Tue, 28 Aug 2001 14:07:01 -0400
This is a multi-part message in MIME format.
------=_NextPart_000_0019_01C12FCA.B54B6140
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
ahhh i thought dman was the only one that was gonna respond for awile so =
i guess i'll just post a follow up like this (even though i already sent =
it to dman) i think i figured out the whole function thing check it out =
lemme know if im a fruit
def circle_area():
print "would you like to input radius or diameter?"
print "1. radius"
print "2. diameter"
question =3D input ("> ")
if question =3D=3D 1:
print "what is the radius?"
radius =3D input("> ")
radius =3D 3.14*radius**2
print radius
elif question =3D=3D 2:
print "what is the diameter?"
diameter =3D input ("> ")
diameter =3D diameter/2
diameter =3D diameter**2 * 3.14
print diameter
options =3D {
"1" : circle_area ,
#"2" : square_area ,
#"3" : rectangle_area ,
#"4" : square_root ,
#"5" : add_numbers ,
}
#Then you would have the following for your "main" loop :
print "alright now for some real math\n"
while 1:
print "please choose an option"
print
print "1. circle area"
print "2. square area"
print "3. rectangle area"
print "4. square root"
print "5. add numbers"
# use raw_input() instead of input() -- there are various security
# holes and issues with using input() in a production environment
# (it is fine for quick-n-dirty testing/prototyping though)
shape =3D raw_input("> ")
# now get the function that handles this operation and let it do
# the real work, be sure to check for errors first
if not options.has_key( shape ) :
print "Error -- %s is not a valid option" % shape
continue # go on with the next iteration of the loop
options[ shape ]()
i commented out a few of the options because i didn't want to take the =
time to define them yet and i'm gonna add a menu option for exit next =
:-) and im gonna try that little menu thing thanks to ignacio.....you =
guys are great thanks for the help lol i'll be sure to ask you guys lots =
of questions=20
------=_NextPart_000_0019_01C12FCA.B54B6140
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.4134.100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>ahhh i thought dman was the only one =
that was gonna=20
respond for awile so i guess i'll just post a follow up like this (even =
though i=20
already sent it to dman) i think i figured out the whole function thing =
check it=20
out lemme know if im a fruit</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>def =
circle_area():<BR> print=20
"would you like to input radius or diameter?"<BR> =
print "1.=20
radius"<BR> print "2. diameter"<BR> =
question=20
=3D input ("> ")<BR> if question =3D=3D=20
1:<BR> print "what is the=20
radius?"<BR> radius =3D =
input(">=20
")<BR> radius =3D=20
3.14*radius**2<BR> print=20
radius<BR> elif question =3D=3D=20
2:<BR> print "what is the=20
diameter?"<BR> diameter =3D =
input (">=20
")<BR> diameter =3D=20
diameter/2<BR> diameter =3D =
diameter**2=20
* 3.14<BR> print =
diameter</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>options =3D {<BR> "1" =
: circle_area=20
,<BR> #"2" : square_area ,<BR> #"3" =
:=20
rectangle_area ,<BR> #"4" : square_root=20
,<BR> #"5" : add_numbers ,<BR> =20
}</FONT></DIV>
<DIV> </DIV><FONT face=3DArial size=3D2>
<DIV><BR>#Then you would have the following for your "main" loop :</DIV>
<DIV> </DIV>
<DIV>print "alright now for some real math\n"<BR>while =
1:<BR> =20
print "please choose an option"<BR> =20
print<BR> print "1. circle area"<BR> =
print=20
"2. square area"<BR> print "3. rectangle=20
area"<BR> print "4. square root"<BR> =
print=20
"5. add numbers"</DIV>
<DIV> </DIV>
<DIV> # use raw_input() instead of input() -- there =
are=20
various security<BR> # holes and issues with using =
input() in=20
a production environment<BR> # (it is fine for =
quick-n-dirty=20
testing/prototyping though)<BR> shape =3D =
raw_input(">=20
")</DIV>
<DIV> </DIV>
<DIV> # now get the function that handles this =
operation and=20
let it do<BR> # the real work, be sure to check for =
errors=20
first<BR> if not options.has_key( shape )=20
:<BR> print "Error -- %s is =
not a=20
valid option" % shape<BR> =
continue #=20
go on with the next iteration of the loop</DIV>
<DIV> </DIV>
<DIV> options[ shape ]()<BR></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>i commented out a few of the options because i didn't want to take =
the time=20
to define them yet and i'm gonna add a menu option for exit next :-) and =
im=20
gonna try that little menu thing thanks to ignacio.....you guys are =
great thanks=20
for the help lol i'll be sure to ask you guys lots of questions=20
</DIV></FONT></BODY></HTML>
------=_NextPart_000_0019_01C12FCA.B54B6140--