def calcSA(shape): if shape == "cube": x = input() SA = 6 * (x ** 2) elif shape == "cuboid": x = input() y = input() z = input() SA = 2*x*y + 2*x*z + 2*y*z elif shape == "cylinder": r = input() h = input() SA = 2*3.1415*r*h+2*3.1415*(r**2) else: print shape + " is not a valid option. Valid options are cube, cuboid, or cylinder" return SA def CalcVolume(shape): if shape == "cube": x = input() volume = x ** 3 elif shape == "cuboid": x = input() y = input() z = input() volume = x*y*z elif shape == "cylinder": r = input() h = input() volume = 3.1415 * (r ** 2) * h else: print shape + " is not an option. Please enter a different shape." return volume def CalcArea(shape): if shape == "rectangle" or shape == "parallelogram": width = input("Please enter a width: ") height = input("Please enter a height: ") area = width * height elif shape == "triangle": base = input("Please enter a base: ") height = input("Please enter a height: ") area = 0.5 * base * height elif shape == "circle": radius = input("Please enter a radius: ") area = 3.1415 * (radius ** 2) elif shape == "square": length = input("Please enter a side length: ") area = length ** 2 elif shape == "ellipse": a = input() b = input() area = 3.1415 * a * b elif shape == "trapezoid": a = input() b = input() h = input() area = 0.5*(a+b)*h else: print shape + " is not a valid option. Please enter another shape." return area option = input() shape = input() def CalcAnything(option, shape): if option == "Area": area = CalcArea(shape) return area elif option == "Surface Area": SA = calcSA(shape) return SA elif option == "Volume": Volume = CalcVolume(shape) return Volume else: print option + " is not valid for " + shape print(CalcAnything(option, shape))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question