View Single Post
Old Dec 9th, 2005, 11:18 PM   #1
snipertomcat
Programmer
 
snipertomcat's Avatar
 
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 4 snipertomcat is on a distinguished road
New to Functions

Hi. This is my first program with the use of functions. Could I get some opinions? Could it be improved at all?

#By Snipertomcat
#Area Calculator w/ menu interface

def menu_options(): #Getting all the def's squared away
    print "Welcome to Area-Calc."
    print "Options:"
    print "  'p' print options"
    print "  'r' calculate area of a rectangle "
    print "  's' calculate area of a square "
    print "  'c' calculate area of a circle "
    print "  'q' quit the program"

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

def area_square(num):
        return num*num
    
def area_circle(radius):
    return 3.14 * radius **2

menu_options() #Program starts here

choice = "p"
while choice != "q":
    if choice == "r":
        w = input("Rectangle width: ")
        h = input("Rectangle hight: ")
        print "The area is: ",area_rec(w,h)
    elif choice == "s":
        squarenum = input("Square length: ")
        print "The area is: ", area_square(squarenum)
    elif choice == "c":
        rad = input("Radius: ")
        print "The area is: ", area_circle(rad)
    choice = raw_input("Option: ")
snipertomcat is offline   Reply With Quote