Advertisement
Sim0o0na

Figures Area

May 3rd, 2018
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # 1. Read figure type
  2. import math
  3.  
  4. figure_type = input()
  5.  
  6. # 2. Check if:
  7. #   a: square -> read "a" // calc
  8. #   b: rectangle -> read width and length // calc
  9. #   c: circle -> read radius
  10. #   d: triangle -> read "a" and ha
  11.  
  12. a = float(input())
  13. area = 0
  14.  
  15. if figure_type == "square":
  16.     area = a * a
  17. elif figure_type == "rectangle":
  18.     b = float(input())
  19.     area = a * b
  20. elif figure_type == "circle":
  21.     # pi * r * r
  22.     area = math.pi * math.pow(a, 2)
  23. elif figure_type == "triangle":
  24.     height = float(input())
  25.     area = a * height / 2
  26.  
  27. print("%.2f" % area)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement