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.
1# Take two angles2angle1 = float(input("Enter first angle: "))3angle2 = float(input("Enter second angle: "))45# Calculate third angle6third_angle = 180 - angle1 - angle278# Validate9if 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
Read the first two angles.
- 2
Subtract both from one hundred eighty.
- 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.
๐Related Content
- ๐
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- ๐
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- ๐ป
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum