Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. # Should return triangle type:
  2. # 0 : if triangle cannot be made with given sides
  3. # 1 : acute triangle
  4. # 2 : right triangle
  5. # 3 : obtuse triangle
  6.  
  7. def triangle_type(a, b, c):
  8. x, y, z = '', '', ''
  9. n = [a, b, c]
  10. res = ''
  11.  
  12. for i in range(3):
  13. if x == '' or n[i] > x:
  14. y, z, x = x, y, n[i]
  15. elif y == '' or n[i] > y:
  16. z, y = y, n[i]
  17. else: z = n[i]
  18.  
  19. if not y + z > x:
  20. res = 0
  21. elif x*x < y*y + z*z:
  22. res = 1
  23. elif x*x == y*y + z*z:
  24. res = 2
  25. elif x*x > y*y + z*z:
  26. res = 3
  27.  
  28. return res
  29.  
  30. print(triangle_type(2, 4, 6) == 0)
  31. print(triangle_type(8, 5, 7) == 1)
  32. print(triangle_type(3, 4, 5) == 2)
  33. print(triangle_type(7, 12, 8) == 3)
  34. print(triangle_type(7, 6, 7) == 1)
  35. print(triangle_type(1, 12, 12) == 1)
  36. print(triangle_type(1, 2, 1) == 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement