Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def ask(question):
  answer = -1
  # apply some sort of validation
  while answer < 0:
    try:
      answer = int(input(question))
    except:
      answer = -1
  return answer

side = []
for n in range(1,4):
  # ask for three sides and add to a list
  side.append(ask("Enter the length of side "+str(n)+": "))
# sort the sides to facilitate comparison
side.sort()
# as they're sorted, only need to check first and last
equilateral = side[0] == side[2]
print("Equilateral triangle: ", equilateral)
# two sides the same?
print("Isosceles triangle: ", (side[0] == side[1] or side[1] == side[2]) and not equilateral)
# all sides different
print("Scalene triangle: ", side[0] != side[1] and side[1] != side[2])
# right-angled triangles have a² = b² + c², where
# a is the longest side and b and c are the others
# (as they're sorted we know side[2] is the longest)
print("Right-angled triangle:", side[2]**2 == side[0]**2 + side[1]**2)