# Build a simple menu system to perform simple calculations
# to work out the area for a circle, rectangle or square

# Get a length (float) from the user
# The text is a string to characterise the type of length
# prompt at the user prompt
def getlength(text):
    """getlength(string) -> float"""
    prompt="Please enter the "+text+": "
    length = float(raw_input(prompt))
    return length

def calcarea(shape,length1,length2=1):
    area = 0.0
    if shape == "circle":
        area=3.142*length1**2.0
    elif shape == "rectangle":
        area=length1*length2
    elif shape == "square":
        area=length1**2.0
    else:
        # No idea
        print "*** ERROR unrecognised shape \"%s\" ***" % shape
    return area

def menu():
    """menu() -> integer\n\nDisplay menu options, get user choice and return option number"""
    while True:
        print "----------------------------------------"
        print "Choose which shape of area to calculate:"
        print "1. Circle"
        print "2. Rectangle"
        print "3. Square"
        print "Any other value exits the program."
        choice=int(raw_input("Enter your selection: "))
        if choice == 1:
            radius=getlength("radius")
            area=calcarea("circle",radius)
        elif choice == 2:
            height=getlength("height")
            width=getlength("width")
            area=calcarea("rectangle",height,width)
        elif choice == 3:
            width=getlength("width")
            area=calcarea("square",width)
        else:
            # Exit
            return
        print
        print "Area = ",area
        print

# Main program
menu()
