[Tutor] list with area calculation
Christoffer Thomsen
christoffer81 at mail.dk
Wed Dec 3 22:34:51 EST 2003
I want to make a program which calculates areas. And I want to select
which kid of area calculation it should be from a list, but I just can't
make it work. I am not surprise if it just some stupid mistake but I
can't figure it out.
#This program calculates areas
print
print "Welcome to calculation program"
print
def print_options() :
print "options:"
print " 'p' print options"
print " 's' calculates square"
print " 'r' calculates rectangle"
print " 'p' calculates perimeter"
print " 'c' calculates circle"
print " 'q' quit program"
def square(width):
return width**2
def rectangle(width,height):
return width*height
def perimeter(width,height):
return (width*2)+(height*2)
def circle(radius):
return 3.14*radius**2
choice = "p"
while choice != "q":
if choice == "s":
width = input("Type width:")
print "Area is: ", square(width)
elif choice == "r":
width = input("Type width:")
height = input("Type height:")
print "Area is: ", rectangle(width,height)
elif choice == "p":
width = input("Type width:")
height = input("Type height:")
print "Area is: ", perimeter(width,height)
elif choice == "c":
radius = input("Type radius:")
print "Area is: ", circle(radius)
elif choice != "q":
print_options()
choice = raw_input("option: ")
More information about the Tutor
mailing list