Calculate Third Angle

Take two angles of a triangle and compute the third angle.

Logic BuildingIntermediate
Logic Building
# Take two angles
angle1 = float(input("Enter first angle: "))
angle2 = float(input("Enter second angle: "))

# Calculate third angle
third_angle = 180 - angle1 - angle2

# Validate
if third_angle > 0 and angle1 > 0 and angle2 > 0:
    print(f"Third angle: {third_angle} degrees")
else:
    print("Invalid triangle angles")

Output

Enter first angle: 60
Enter second angle: 60
Third angle: 60.0 degrees

Enter first angle: 90
Enter second angle: 45
Third angle: 45.0 degrees

Sum of angles in triangle is 180 degrees.

Key Concepts:

  • Third angle = 180 - angle1 - angle2
  • Validate that all angles are positive
  • Check if valid triangle