lamiastella

is_triangle_correct

Jun 22nd, 2016
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. '''
  2. Implement a method that accepts 3 integer values a, b, c. The method should return
  3. true if a triangle can be built with the sides of given length and false in any
  4. other case. (In this case, all triangles must have surface greater than 0 to be accepted).
  5. '''
  6.  
  7. def is_triangle(a, b, c):
  8.     for side in [a, b, c]:
  9.         if side <= 0:
  10.             return False
  11.     sides = [ [a, b, c], [b, a, c], [c, a, b]]
  12.     for side in sides:
  13.         if side[0] + side[1] < side[2]:
  14.             return False
  15.         if abs(side[0] - side[1]) >= side[2]:
  16.             return False
  17.     return True
  18.  
  19. print(is_triangle(7, 2, 2))
  20. print(is_triangle(4, 2, 3))
  21. print(is_triangle(1, 2, 3))
Advertisement
Add Comment
Please, Sign In to add comment