[Tutor] Help with functions

mikew@screaminet.com mikew@screaminet.com
Tue, 18 Jun 2002 11:34:22 GMT


One problem I found when I cut and pasted your code was the line that says if choice="as"; it should read if choice=="as". Another line below that is also wrong in the same way. After I fixed that it ran fine for me.

----- Original Message -----
From:  "Guess Who? Me" <beercanz@hotmail.com>
To:  tutor@python.org
Sent: Tue, 18 Jun 2002 02:04:10 +0000
Subject:  [Tutor] Help with functions
<div style='background-color:'><DIV><FONT size=2>def area_square(side):
    return side*side</FONT></DIV>
<DIV><FONT size=2>def area_rectangle(length,width):
    return length*width</FONT></DIV>
<DIV><FONT size=2>def area_circle(radius):
    return radius*radius*3.14</FONT></DIV>
<DIV><FONT size=2>def print_options():
    print "Options:"
    print "'p' to print options."
    print "'as' for area of a square."
    print "'ar' for area of a rectangle."
    print "'ac' for area of a circle."
    print "'q' to quit."</FONT></DIV>
<DIV><FONT size=2>choice="p"
while choice !="q":
    print_options()
    choice=raw_input("Option?:")
    if choice= "as":
        side=input("What is the length of a side?:")
        print area_square(side)
    if choice=="ar":
        length=input("What is the length?:")
        width=input("What is the width?:")
        print area_rectangle(length,width)
    if choice="ac":
        radius=input("What is the radius?:")
        print area_circle(radius)
print "Thanks for using my program."</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>That is my source code so far. I'm following the tutorial at <A href="http://www.honors.montana.edu/~jjc/easytut/easytut/node9.html">http://www.honors.montana.edu/~jjc/easytut/easytut/node9.html</A></FONT></DIV>
<DIV><FONT size=2>and I had a question. Every time I try to get a function to ask for the input of the sides, lenght, width, whatever, it doesn't work. Something funny I found out is that it might work, but then when I quit python and open it again, it doesn't work, saying that ''length' is not defined'. Any thoughts??</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>Thanks!</FONT></DIV></div><br clear=all><hr>Get your FREE download of MSN Explorer at <a href='http://g.msn.com/1HM505401/44'>http://explorer.msn.com</a>.



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor