[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>&nbsp;&nbsp;&nbsp; return side*side</FONT></DIV>
<DIV><FONT size=2>def area_rectangle(length,width):<BR>&nbsp;&nbsp;&nbsp; return length*width</FONT></DIV>
<DIV><FONT size=2>def area_circle(radius):<BR>&nbsp;&nbsp;&nbsp; return radius*radius*3.14</FONT></DIV>
<DIV><FONT size=2>def print_options():<BR>&nbsp;&nbsp;&nbsp; print "Options:"<BR>&nbsp;&nbsp;&nbsp; print "'p' to print options."<BR>&nbsp;&nbsp;&nbsp; print "'as' for area of a square."<BR>&nbsp;&nbsp;&nbsp; print "'ar' for area of a rectangle."<BR>&nbsp;&nbsp;&nbsp; print "'ac' for area of a circle."<BR>&nbsp;&nbsp;&nbsp; print "'q' to quit."</FONT></DIV>
<DIV><FONT size=2>choice="p"<BR>while choice !="q":<BR>&nbsp;&nbsp;&nbsp; print_options()<BR>&nbsp;&nbsp;&nbsp; choice=raw_input("Option?:")<BR>&nbsp;&nbsp;&nbsp; if choice == "as":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; side=input("What is the length of a side?:")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print area_square(side)<BR>&nbsp;&nbsp;&nbsp; if choice=="ar":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; length=input("What is the length?:")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width=input("What is the width?:")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print area_rectangle(length,width)<BR>&nbsp;&nbsp;&nbsp; if choice =="ac":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; radius=input("What is the radius?:")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print area_circle(radius)<BR>print "Thanks for using my program."</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</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>&nbsp;</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>