Skip to Main Content
Blog

Check Triangle Type in Python

Check Triangle Type in Python

Enter angle x: 45
Enter angle y: 45
Enter angle z: 90
Right Isosceles Triangle
def main():
	x = int(input("Enter angle x: "))
	y = int(input("Enter angle y: "))
	z = int(input("Enter angle z: "))

	# Check if the angles can form a triangle
	if x <= 0 or y <= 0 or z <= 0 or x + y + z != 180:
		print("Not a Triangle")
		return

	# Find the triangle type based on the angles
	if x > 90 or y > 90 or z > 90:
		aType = "Obtuse"
	elif x == 90 or y == 90 or z == 90:
		aType = "Right"
	else:
		aType = "Acute"

	# Find the triangle type based on the equality of angles (proxy for sides)
	if x == y and y == z:
		sType = "Equilateral"
	elif x == y or y == z or x == z:
		sType = "Isosceles"
	else:
		sType = "Scalene"

	print(f"{aType} {sType} Triangle")


if __name__ == "__main__":
	main()