Newbia alert .. working my way through Easy Python Montana Edu page, need help..

Dennis Lee Bieber wlfraed at ix.netcom.com
Sat Sep 21 00:43:52 CEST 2002


Highwaykind fed this fish to the penguins on Friday 20 September 2002 
06:27 am:

> I'm asked ( on the website : www.honors.montana.edu\_jjc\easytut
> \node10.html ) to write a small programm to calculate rectangle,
> square and circle thingies( forgot the English word .. ) and I came up
> with this code :
> 
        <snip>

> But the thing keeps telling me width is not defined, also I can;t use
> the ELIF command .. THink I could do with some help :)
>

        Where to begin... I see way too many errors to intersperse corrections.

1)      Python indentation controls block structure!
2)      You never assign values to those names it is complaining about -- 
rather you are inputting to "a", "b", etc. but never passing /those/ to 
the functions.

        Compare:

import math     #get the long definition of PI

def area_rect(width, height):
        return width * height

def area_square(side):          # squares are special rectangles
        return area_rect(side, side)

def area_circle(radius)
        return math.pi * (radius * radius)      # r*r is likely faster than r**2


option = "prompt"       #filler for first pass
while option != "q":
        if option == "r":
                w = input("Width")
                h = input("Height")
                print "Area of Rectangle is ", area_rect(w, h)

        elif option == "s":
                s = input("Side")
                print "Area of Square is ", area_square(s)

        elif option == "c":
                r = input("Radius")
                print "Area of Circle is ", area_circle(r)

        else:
                print "Options:"
                print " 'r'     Calculate Area of Rectangle"
                print " 's'     Calculate Area of Square"
                print " 'c'     Calculate Area of Circle"
                print " 'q'     Quit program"
                print " <other> Display this help"

        option = raw_input("Option")


--
 > ============================================================== <
 >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed at dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <



More information about the Python-list mailing list