Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Should return triangle type:
- # 0 : if triangle cannot be made with given sides
- # 1 : acute triangle
- # 2 : right triangle
- # 3 : obtuse triangle
- def triangle_type(a, b, c):
- x, y, z = '', '', ''
- n = [a, b, c]
- res = ''
- for i in range(3):
- if x == '' or n[i] > x:
- y, z, x = x, y, n[i]
- elif y == '' or n[i] > y:
- z, y = y, n[i]
- else: z = n[i]
- if not y + z > x:
- res = 0
- elif x*x < y*y + z*z:
- res = 1
- elif x*x == y*y + z*z:
- res = 2
- elif x*x > y*y + z*z:
- res = 3
- return res
- print(triangle_type(2, 4, 6) == 0)
- print(triangle_type(8, 5, 7) == 1)
- print(triangle_type(3, 4, 5) == 2)
- print(triangle_type(7, 12, 8) == 3)
- print(triangle_type(7, 6, 7) == 1)
- print(triangle_type(1, 12, 12) == 1)
- print(triangle_type(1, 2, 1) == 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement