[Tutor] Help with functions
Guess Who? Me
beercanz@hotmail.com
Tue, 18 Jun 2002 02:04:10 +0000
<html><div style='background-color:'><DIV><FONT size=2>def area_square(side):<BR> return side*side</FONT></DIV>
<DIV><FONT size=2>def area_rectangle(length,width):<BR> return length*width</FONT></DIV>
<DIV><FONT size=2>def area_circle(radius):<BR> return radius*radius*3.14</FONT></DIV>
<DIV><FONT size=2>def print_options():<BR> print "Options:"<BR> print "'p' to print options."<BR> print "'as' for area of a square."<BR> print "'ar' for area of a rectangle."<BR> print "'ac' for area of a circle."<BR> print "'q' to quit."</FONT></DIV>
<DIV><FONT size=2>choice="p"<BR>while choice !="q":<BR> print_options()<BR> choice=raw_input("Option?:")<BR> if choice == "as":<BR> side=input("What is the length of a side?:")<BR> print area_square(side)<BR> if choice=="ar":<BR> length=input("What is the length?:")<BR> width=input("What is the width?:")<BR> print area_rectangle(length,width)<BR> if choice =="ac":<BR> radius=input("What is the radius?:")<BR> print area_circle(radius)<BR>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>.<br></html>