[Tutor] Re Help with this script
John Carmona
jeannot18 at hotmail.com
Sat Apr 23 16:44:48 CEST 2005
Thanks Kent, it is working now. Is this what you meant in your reply?
Because if I set up the main code at the end of the script I was still
getting an error message.
Also, what do I need to use if for example I want my code to rerun once I
have computed let's say a volume. Right now the execution of the script
gives me "None" at the end.
Thanks
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*width
def 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*side
def 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/2
def vol_sph():
radius = input("What is the radius?: ")
print "The volume is: ", (4*3.14159*radius**3)/3
def vol_cube():
side = input("Side: ")
print "The volume is: ",side**3
def 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*depth
def 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: ", (1/3)(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 "------------------------------"
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 "------------------------------"
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()
elif choice == 'f':
print_options()
def 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 "------------------------------"
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()
#Call starting menu
print task_options()
----------------------------------------------------------------------------------------------------------
More information about the Tutor
mailing list