In: Computer Science
“Triangle Guessing” game in Python
The program accepts the lengths of three (3) sides of a triangle as input . The program output should indicate if the triangle is a right triangle, an acute triangle, or an obtuse triangle.
SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly indented for better understanding.
while True:
try:
# Check for numbers
a,b,c = input('Enter 3 numbers (sides of a triangle) : ').split()
a,b,c = int(a),int(b),int(c)
except:
print('Please Enter only Numbers..')
continue
# Only positive numbers are accepted
if a<0 or b<0 or c<0:
print('Invalid Numbers. Only Positive Numbers are accepted.')
print('Please Try Again,,,!')
continue
# Validate triangle
if not (a+b > c or b+c >a or a+c > b):
print('Invalid Sides. These will not form a triangle.')
else:
if a>b and b>c:
longest = a
other_side1=b
other_side2=c
elif b>c:
longest=b
other_side1=a
other_side2=c
else:
longest = c
other_side1 = b
other_side2 = a
if longest**2 == other_side1**2 + other_side2**2:
print('These sides form a right angled triangle.!!')
elif longest**2 < other_side1**2 + other_side2**2:
print('These sides form an acute triangle.!!')
else:
print('These sides form an obtuse triangle.!!')
choice = input('Do you want to continue:(Y/N)')
if not choice=='Y':
break
print('Bye!!')
=======================
SCREENSHOT:


OUTPUT SAMPLE:

