Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # area_calculator.py
- import math
- shapes = '''
- Square
- Triangle
- Circle
- Rectangle
- Rhombus
- Trapezoid
- Quadrillateral
- Sector
- Ellipse
- Prism
- Regular Polygon
- '''
- c=shapes.split('\n')
- shapes=''
- for a, b in enumerate(c[1:-1]):
- a=str(a).zfill(2)
- shapes += a+'.) '+b+'\n'
- def get_shape_area():
- print shapes
- shape=int(input("What shape are you looking for the area of? "))
- if shape==0:
- square()
- elif shape==1:
- triangle()
- elif shape==2:
- circle()
- elif shape==3:
- rectangle()
- elif shape==4:
- rhombus()
- elif shape==5:
- trapezoid()
- elif shape==6:
- quadrillateral()
- elif shape==7:
- sector()
- elif shape==8:
- ellipse()
- elif shape==9:
- prism()
- elif shape==10:
- reg_polygon()
- else:
- print("Error: Select a number on the list: ")
- def rectangle():
- h=int(input("What is the height of the rectangle? "))
- w=int(input("What is the width of the rectangle? "))
- area=w*h
- print("The area of the rectangle is...")
- print(area)
- def circle():
- r=int(input("What is the radius of the circle? "))
- area=math.pi*r*r
- print("The area of the circle is...")
- print(area)
- def square():
- h=int(input("What is the height of the square? "))
- area=h*h
- print("The area of the square is...")
- print(area)
- def triangle():
- w=int(input("What is the width of the base of the triangle? "))
- h=int(input("What is the height of the triangle? "))
- area=w*h*0.5
- print("The area of the triangle is...")
- print(area)
- def rhombus():
- c=int(input("What is the length of diagonal 1? "))
- d=int(input("What is the length of diagonal 2? "))
- area=0.5*c*d
- print("The area of the rhombus is...")
- print(area)
- def trapezoid():
- a=int(input("What is the length of the first parallel side? "))
- b=int(input("What is the length of the second parallel side? "))
- h=int(input("What is the altitude of the trapezoid? "))
- area=0.5*(a+b)*h
- print("The area of the trapezoid is...")
- print(area)
- def quadrillateral():
- a=int(input("What is the length of diagonal 1? "))
- b=int(input("What is the length of diagonal 2? "))
- angle=int(input("What is the angle between the diagonals? "))
- area=0.5*a*b*math.sin(angle)
- print("The area of the quadrillateral is...")
- print(area)
- def reg_polygon():
- n=int(input("How many sides? "))
- l=int(input("Length of each side? "))
- area=(n*l**2)/(4*math.tan((180/n)*(math.pi/180)))
- print("The area of the regular polygon is...")
- print(area)
- def sector():
- angle=int(input("What is the angle between the radii? "))
- pi=math.pi
- r=int(input("What is the radius? "))
- area=(pi*(r*r)*angle)/360
- print("The area of the sector is...")
- print(area)
- def ellipse():
- a=int(input("What is the first semiaxes? "))
- b=int(input("What is the second semiaxes? "))
- pi=math.pi
- area=pi*a*b
- print("The area of the ellipse is...")
- print(area)
- def prism():
- a=int(input("What is the perimeter of a right section of the prism? "))
- b=int(input("What is the length of the prism? "))
- area=a*b
- print("The lateral area of the regular prism is...")
- print(area)
- #
- while 1:
- get_shape_area()
- print
- user_input = raw_input('Calculate More (y/n) ? ')
- print
- if user_input.lower() != 'y':
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement