[Tutor] how to rewrite area.py

William Stewart williamjstewart at rogers.com
Wed Feb 22 00:51:39 CET 2012

I need to rewrite area.py program so that it has separate functions for the perimeter and area of a square, a rectangle, and a circle (3.14 * radius**2). 
I am horrible at math and I cannot even figure out what I need to do for this
Any help would be appreciated

All I have is the menu which looks like this
import math
print "your options are:"
print " "
print "1) Area(SQUARE)"
print "2) Area(RECTANGLE)"
print "3) Area(CIRCLE)"
print "4) Perimeter(SQUARE)"
print "5) Perimeter(RECTANGLE)"
print "6) Perimeter(CIRCLE)"
print "7) Exit"
while True: 
    selection = raw_input("Please select an option from the menu.: ")
python area.py

print "Calculate information about a rectangle"
length = input("Length:")
width = input("Width:")
print "Area",length*width
print "Perimeter",2*length+2*width
print 'To find the area of a rectangle,'
print 'Enter the width and height below.'
w = input('Width:  ')
while w <= 0:
    print 'Must be a positive number'
    w = input('Width:  ')
h = input('Height: ')
while h <= 0:
    print 'Must be a positive number'
    h = input('Height: ')
print 'Width =',w,' Height =',h,' so Area =',area(w,h)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120221/7cf9ef80/attachment.html>

More information about the Tutor mailing list