Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

Calculate Third Angle

Calculate a triangle's third angle and reject nonpositive angles. Students follow float input, subtraction, and three conditions needed for a valid result.

IntermediatePhase 1 - Level 3: Math and Number LogicExample 9 of 10
calculate-third-angle.py
1# Take two angles
2angle1 = float(input("Enter first angle: "))
3angle2 = float(input("Enter second angle: "))
4
5# Calculate third angle
6third_angle = 180 - angle1 - angle2
7
8# Validate
9if third_angle > 0 and angle1 > 0 and angle2 > 0:
10 print(f"Third angle: {third_angle} degrees")
11else:
12 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

In this one

  • Use the angle-sum rule
  • Validate all three angles
  • Separate calculation from acceptance

How it works

  1. 1

    Read the first two angles.

  2. 2

    Subtract both from one hundred eighty.

  3. 3

    Print the result only if every angle is positive.

Edge cases

What if the inputs sum to 180?

What if the inputs sum to 180?

The third angle is zero, so the triangle is rejected.

What if one input is negative?

What if one input is negative?

The explicit positivity check rejects it even if the computed third angle is positive.

What's going on

Triangle angles add to one hundred eighty degrees in ordinary plane geometry. The code subtracts the two entered angles from that total before deciding whether to display the result.

A positive third angle is not enough by itself; both entered angles must also be positive. All three requirements are joined by and. For 90 and 45, the remaining angle is 45.0 degrees.

What if the inputs sum to 180? The third angle is zero, so the triangle is rejected.

What if one input is negative? The explicit positivity check rejects it even if the computed third angle is positive.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

Which calculation finds the third angle?

Pick an answer to check it.

Question 2

What if the inputs sum to 180?

Pick an answer to check it.

Questions people ask

What if the inputs sum to 180?

The third angle is zero, so the triangle is rejected.

What if one input is negative?

The explicit positivity check rejects it even if the computed third angle is positive.

Which calculation finds the third angle?

180 - angle1 - angle2.