#This program takes in a shape and returns an area shape = input("Please enter a shape: ") 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 area1 = CalcArea(shape) print(area1)
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