Cha0tic

05-04-2014, 02:52 PM

Hey brahs working on some HW and having a issue with my code, my second set of if and elif statesment are not executing.

They aren't giving me any errors its just as if they are being skipped over.

Here's the code and mind checking if I'm doing what is required.

def main():

#input section

print ("Caluclate the Volume of: ")

print ("\t", "1)Box\n"

"\t", "2)Cylinder\n"

"\t", "3)Pyramid\n"

"\t", "4)Sphere\n"

"\t", "5)Exit\n")

choice = int(input("Enter Choice :"))

if choice == 1:

print ("You choose to calculate the volume of a Box.")

boxlength = float(input("Enter Length of the box: " ))

boxwidth = float(input("Enter Width of the Box : "))

boxheight = float(input("Enter Height of the Box : "))

elif choice == 2:

print ("You choose to calculate the volume of a Cylinder.")

cylinderradius = float(input("Enter Radius of the Cylinder: "))

cylinderheight = float(input("Enter Height of the Cylinder: "))

elif choice == 3:

print("You choose to calculate the volume of a Pyramid.")

pybase = float(input("Enter the Base of the Pyramid : "))

pyheight = float(input("Enter the Height of the Pyramid : "))

elif choice == 4:

print ("You choose to caluclate the volume of a Sphere.")

sphereradius = float(input("Enter the Radius of the Sphere : "))

elif choice == 5:

print("Press any key to exit.")

while choice > 5:

print ("Not Valid Choice")

choice = int(input("Enter Choice :"))

#processing section

from math import math

from fractions import Fraction

boxvolume = length*width*height

cylindervolume = math.pi*(radius ** 2)*height

pyramidvolume = Fraction(1, 3)* (base ** 2) * height

spherevolume = Fraction(4, 3) * math.pi * radius**3

#output section

if choice == 1:

print ("Calculating the Volume of a Box\n"

"With a Length of", boxlength, "With a Width of", boxwidth, "With a Height of", boxheight)

elif choice == 2:

print("Calculating the Volume of a Cylinder\n"

"With a Radius of",cylinderradious, "With a Height", cylinderheight)

elif choice == 3:

print("Calculating the Volume of a Pyramid\n"

"With a Base of", pybase, "With the Height of", pyheight)

elif choice == 4:

print("Calculating the Volume of a Sphere\n"

"With a Radius", sphereradius)

main ()

print("Press any key to continue.")

Requirements

Requirements:

• Comment thoroughly; add comments to identify the variables used and comments explaining each function.

• Relevant data must be Input with proper prompts.

• if .. elif must handle all possible inputs, validate menu choice input

• Use a function to handle the menu.

• Use a function to handle each shape.

• Use upper() method wherever is necessary.

• Each function prints the data related to it.

• The menu() function prints the message and returned volume.

• Printed results should be self explanatory and sufficient.

They aren't giving me any errors its just as if they are being skipped over.

Here's the code and mind checking if I'm doing what is required.

def main():

#input section

print ("Caluclate the Volume of: ")

print ("\t", "1)Box\n"

"\t", "2)Cylinder\n"

"\t", "3)Pyramid\n"

"\t", "4)Sphere\n"

"\t", "5)Exit\n")

choice = int(input("Enter Choice :"))

if choice == 1:

print ("You choose to calculate the volume of a Box.")

boxlength = float(input("Enter Length of the box: " ))

boxwidth = float(input("Enter Width of the Box : "))

boxheight = float(input("Enter Height of the Box : "))

elif choice == 2:

print ("You choose to calculate the volume of a Cylinder.")

cylinderradius = float(input("Enter Radius of the Cylinder: "))

cylinderheight = float(input("Enter Height of the Cylinder: "))

elif choice == 3:

print("You choose to calculate the volume of a Pyramid.")

pybase = float(input("Enter the Base of the Pyramid : "))

pyheight = float(input("Enter the Height of the Pyramid : "))

elif choice == 4:

print ("You choose to caluclate the volume of a Sphere.")

sphereradius = float(input("Enter the Radius of the Sphere : "))

elif choice == 5:

print("Press any key to exit.")

while choice > 5:

print ("Not Valid Choice")

choice = int(input("Enter Choice :"))

#processing section

from math import math

from fractions import Fraction

boxvolume = length*width*height

cylindervolume = math.pi*(radius ** 2)*height

pyramidvolume = Fraction(1, 3)* (base ** 2) * height

spherevolume = Fraction(4, 3) * math.pi * radius**3

#output section

if choice == 1:

print ("Calculating the Volume of a Box\n"

"With a Length of", boxlength, "With a Width of", boxwidth, "With a Height of", boxheight)

elif choice == 2:

print("Calculating the Volume of a Cylinder\n"

"With a Radius of",cylinderradious, "With a Height", cylinderheight)

elif choice == 3:

print("Calculating the Volume of a Pyramid\n"

"With a Base of", pybase, "With the Height of", pyheight)

elif choice == 4:

print("Calculating the Volume of a Sphere\n"

"With a Radius", sphereradius)

main ()

print("Press any key to continue.")

Requirements

Requirements:

• Comment thoroughly; add comments to identify the variables used and comments explaining each function.

• Relevant data must be Input with proper prompts.

• if .. elif must handle all possible inputs, validate menu choice input

• Use a function to handle the menu.

• Use a function to handle each shape.

• Use upper() method wherever is necessary.

• Each function prints the data related to it.

• The menu() function prints the message and returned volume.

• Printed results should be self explanatory and sufficient.