[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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>def =
circle_area():<BR>&nbsp;&nbsp;&nbsp; print=20
"would you like to input radius or diameter?"<BR>&nbsp;&nbsp;&nbsp; =
print "1.=20
radius"<BR>&nbsp;&nbsp;&nbsp; print "2. diameter"<BR>&nbsp;&nbsp;&nbsp; =
question=20
=3D input ("&gt; ")<BR>&nbsp;&nbsp;&nbsp; if question =3D=3D=20
1:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "what is the=20
radius?"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; radius =3D =
input("&gt;=20
")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; radius =3D=20
3.14*radius**2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
radius<BR>&nbsp;&nbsp;&nbsp; elif question =3D=3D=20
2:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "what is the=20
diameter?"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diameter =3D =
input ("&gt;=20
")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diameter =3D=20
diameter/2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diameter =3D =
diameter**2=20
* 3.14<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print =
diameter</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>options =3D {<BR>&nbsp;&nbsp;&nbsp; "1" =
: circle_area=20
,<BR>&nbsp;&nbsp;&nbsp; #"2" : square_area ,<BR>&nbsp;&nbsp;&nbsp; #"3" =
:=20
rectangle_area ,<BR>&nbsp;&nbsp;&nbsp; #"4" : square_root=20
,<BR>&nbsp;&nbsp;&nbsp; #"5" : add_numbers ,<BR>&nbsp;&nbsp;&nbsp;=20
}</FONT></DIV>
<DIV>&nbsp;</DIV><FONT face=3DArial size=3D2>
<DIV><BR>#Then you would have the following for your "main" loop :</DIV>
<DIV>&nbsp;</DIV>
<DIV>print "alright now for some real math\n"<BR>while =
1:<BR>&nbsp;&nbsp;&nbsp;=20
print "please choose an option"<BR>&nbsp;&nbsp;&nbsp;=20
print<BR>&nbsp;&nbsp;&nbsp; print "1. circle area"<BR>&nbsp;&nbsp;&nbsp; =
print=20
"2. square area"<BR>&nbsp;&nbsp;&nbsp; print "3. rectangle=20
area"<BR>&nbsp;&nbsp;&nbsp; print "4. square root"<BR>&nbsp;&nbsp;&nbsp; =
print=20
"5. add numbers"</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; # use raw_input() instead of input() -- there =
are=20
various security<BR>&nbsp;&nbsp;&nbsp; # holes and issues with using =
input() in=20
a production environment<BR>&nbsp;&nbsp;&nbsp; # (it is fine for =
quick-n-dirty=20
testing/prototyping though)<BR>&nbsp;&nbsp;&nbsp; shape =3D =
raw_input("&gt;=20
")</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; # now get the function that handles this =
operation and=20
let it do<BR>&nbsp;&nbsp;&nbsp; # the real work, be sure to check for =
errors=20
first<BR>&nbsp;&nbsp;&nbsp; if not options.has_key( shape )=20
:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "Error -- %s is =
not a=20
valid option" % shape<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
continue #=20
go on with the next iteration of the loop</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; options[ shape ]()<BR></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</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--