Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
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
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:41 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC