JC
------------------------------------------------------------------------------------ #By J Carmona #Programme that compute volumes or surfaces ##First menu is for the calculation of area ##Second menu is for the calculation of volume
##First ask the user what he wants to do running = True
def area_rect():
length = input("Length: ")
width = input ("Width: ")
print "The area is: ",length*widthdef area_circ():
radius = input("What is the radius?: ")
print "The area is approximately: ", 3.14159*(radius**2)def area_squ():
side = input ("What is the length of one side?: ")
print "The area is: ", side*sidedef area_tgle():
base = input ("What is the base of the triangle?: ")
heigth = input ("What is the heigth of the triangle?: ")
print "The area is: ",base*heigth/2def vol_sph():
radius = input("What is the radius?: ")
print "The volume is: ", (4*3.14159*radius**3)/3def vol_cube():
side = input("Side: ")
print "The volume is: ",side**3def vol_box():
width = input ("What is the width of the box?: ")
length = input ("What is the length of the box?: ")
depth = input ("What is the depth of the box?: ")
print "The volume is: ", width*length*depthdef vol_cone():
radius = input ("What is the radiux of the base of the cone?: ")
heigth = input ("What is the heigth of the cone?: ")
print "The volume is: ", 0.3333*3.144159*(radius**2)*heigth
def task_options(): print "---------------------------------------" print "Options:" print "a. Print options: " print "b. Do you want to calculate areas?: " print "c. Do you want to calculate volumes?: " print "d. Quit the programme" print "---------------------------------------" choice = raw_input("Choose an option: ") if choice == 'a': print task_options() elif choice == 'b': print print_options() elif choice == 'c': print print_options_2() elif choice == 'd': running = False
def print_options():
print_options
print "------------------------------"
print "Options:"
print "a. print options"
print "b. calculate circle area"
print "c. calculate square area"
print "d. calculate rectangle area"
print "e. calculate triangle area"
print "f. quit the programme"
print "------------------------------"
while 1:
choice = raw_input("Choose an option: ")
if choice == 'a':
print_options()
elif choice == 'b':
area_circ()
elif choice == 'c':
area_squ()
elif choice == 'd':
area_rect()
elif choice == 'e':
area_tgle()
if choice == 'f': breakdef print_options_2():
print "------------------------------"
print "Options:"
print "a. print options"
print "b. calculate the volume of a sphere"
print "c. calculate the volume of a cube"
print "d. calculate the volume of a box"
print "e. calculate the volume of a cone"
print "f. quit the programme"
print "------------------------------"
while 1:
choice = raw_input("Choose an option: ")
if choice == 'a':
print_options()
elif choice == 'b':
vol_sph()
elif choice == 'c':
vol_cube()
elif choice == 'd':
vol_box()
elif choice == 'e':
vol_cone()
elif choice == 'e':
print_options()
if choice == 'f': break#Call starting menu task_options()
------------------------------------------------------------------------------------
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
