""" This program will give you the area of any geometric shape """ import math def area_circle(): r = float(raw_input("Enter the radius of the circle: ")) area = math.pi * (r ** 2) return area def area_parallelogram(): l = float(raw_input("Enter the length of the figure: ")) w = float(raw_input("Enter the width of the figure: ")) area = l * w units = "square " + str(raw_input("Enter the units: ")) return str(area) + " " + units def area_triangle(): b = float(raw_input("Enter the base of the figure: ")) h = float(raw_input("Enter the height of the figure: ")) area = (b*h)/2 units = "square " + str(raw_input("Enter the units: ")) return str(area) + " " + units def area_polygon(): n = int(raw_input("Enter the number of sides the figure has: ")) if n <= 2: return "This is not a valid figure." elif n <= 4: return "Use another function." else: a = float(raw_input("Enter the apothem of the figure: ")) int_angle = 360/n if int_angle/2 == 30 or int_angle/2 == 60: oneside = 2 * (a / (math.sqrt(3))) P = oneside * n area = (P * a) / 2 return area area_polygon()
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