Advertisement
here2share

# area_calculator.py

Jun 7th, 2015
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.16 KB | None | 0 0
  1. # area_calculator.py
  2.  
  3. import math
  4.  
  5. shapes = '''
  6. Square
  7. Triangle
  8. Circle
  9. Rectangle
  10. Rhombus
  11. Trapezoid
  12. Quadrillateral
  13. Sector
  14. Ellipse
  15. Prism
  16. Regular Polygon
  17. '''
  18.  
  19. c=shapes.split('\n')
  20. shapes=''
  21. for a, b in enumerate(c[1:-1]):
  22.     a=str(a).zfill(2)
  23.     shapes += a+'.) '+b+'\n'
  24.    
  25. def get_shape_area():
  26.     print shapes
  27.     shape=int(input("What shape are you looking for the area of? "))
  28.     if shape==0:
  29.         square()
  30.     elif shape==1:
  31.         triangle()
  32.     elif shape==2:
  33.         circle()
  34.     elif shape==3:
  35.         rectangle()
  36.     elif shape==4:
  37.         rhombus()
  38.     elif shape==5:
  39.         trapezoid()
  40.     elif shape==6:
  41.         quadrillateral()
  42.     elif shape==7:
  43.         sector()
  44.     elif shape==8:
  45.         ellipse()
  46.     elif shape==9:
  47.         prism()
  48.     elif shape==10:
  49.         reg_polygon()
  50.     else:
  51.         print("Error: Select a number on the list: ")
  52.  
  53. def rectangle():
  54.     h=int(input("What is the height of the rectangle? "))
  55.     w=int(input("What is the width of the rectangle? "))
  56.     area=w*h
  57.     print("The area of the rectangle is...")
  58.     print(area)
  59.    
  60.  
  61. def circle():
  62.     r=int(input("What is the radius of the circle? "))
  63.     area=math.pi*r*r
  64.     print("The area of the circle is...")
  65.     print(area)
  66.  
  67. def square():
  68.     h=int(input("What is the height of the square? "))
  69.     area=h*h
  70.     print("The area of the square is...")
  71.     print(area)
  72.  
  73. def triangle():
  74.     w=int(input("What is the width of the base of the triangle? "))
  75.     h=int(input("What is the height of the triangle? "))
  76.     area=w*h*0.5
  77.     print("The area of the triangle is...")
  78.     print(area)
  79.  
  80. def rhombus():
  81.     c=int(input("What is the length of diagonal 1? "))
  82.     d=int(input("What is the length of diagonal 2? "))
  83.     area=0.5*c*d
  84.     print("The area of the rhombus is...")
  85.     print(area)
  86.  
  87. def trapezoid():
  88.     a=int(input("What is the length of the first parallel side? "))
  89.     b=int(input("What is the length of the second parallel side? "))
  90.     h=int(input("What is the altitude of the trapezoid? "))
  91.     area=0.5*(a+b)*h
  92.     print("The area of the trapezoid is...")
  93.     print(area)
  94.  
  95. def quadrillateral():
  96.     a=int(input("What is the length of diagonal 1? "))
  97.     b=int(input("What is the length of diagonal 2? "))
  98.     angle=int(input("What is the angle between the diagonals? "))
  99.     area=0.5*a*b*math.sin(angle)
  100.     print("The area of the quadrillateral is...")
  101.     print(area)
  102.  
  103. def reg_polygon():
  104.     n=int(input("How many sides? "))
  105.     l=int(input("Length of each side? "))
  106.     area=(n*l**2)/(4*math.tan((180/n)*(math.pi/180)))
  107.     print("The area of the regular polygon is...")
  108.     print(area)
  109.  
  110. def sector():
  111.     angle=int(input("What is the angle between the radii? "))
  112.     pi=math.pi
  113.     r=int(input("What is the radius? "))
  114.     area=(pi*(r*r)*angle)/360
  115.     print("The area of the sector is...")
  116.     print(area)
  117.  
  118. def ellipse():
  119.     a=int(input("What is the first semiaxes? "))
  120.     b=int(input("What is the second semiaxes? "))
  121.     pi=math.pi
  122.     area=pi*a*b
  123.     print("The area of the ellipse is...")
  124.     print(area)
  125.  
  126. def prism():
  127.     a=int(input("What is the perimeter of a right section of the prism? "))
  128.     b=int(input("What is the length of the prism? "))
  129.     area=a*b
  130.     print("The lateral area of the regular prism is...")
  131.     print(area)
  132. #
  133. while 1:
  134.     get_shape_area()
  135.     print
  136.     user_input = raw_input('Calculate More (y/n) ? ')
  137.     print
  138.     if user_input.lower() != 'y':
  139.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement