Reputation: 131
i try to find an angle of triangle with rules: If the total of the three numbers = 180, then check again: If the three corners of the triangle form an acute angle with a magnitude between 0 ° to 90 °, then print the words "acute angle" If one of the corners is an obtuse angle whose magnitude is between 90 ° to 180 °, then print the words "obtuse angle" If one of the corners is a right angle whose magnitude is 90 °, then print the words "carpenter's triangle" If the total of the three numbers is not 180, then print the words "NOT TRIANGLE"
this my program but i got wrong output:
A = int(input("enter the number of 1 : "))
B = int(input("enter the number of 2 : "))
C = int(input("enter the number of 3 : "))
if(A+B+C <= 90):
print("acute angle")
if( 90>A<=180 or 90>B<=180 or 90>C<=180 ):
print("obtuse angle")
if(A+B+C > 180):
print("NOT TRIANGLE")
break
if(A==90 or B==90 or C==90):
print("carpenter's triangle")
i need your opinion to fix this program
Upvotes: 1
Views: 2573
Reputation: 2233
Here is one solution you can try:
# If sum of angles makes upto 180; then a triangle
if(A+B+C == 180):
# if atleast one side is 90; then Carpenter's triangle
if(A==90 or B==90 or C==90):
print("Carpenter's triangle")
# if all sides are less than 90; then Accute triangle
elif(A<90 and B<90 and C<90):
print("Accute triangle")
# if atleast one side is greater than 90; then Obtuce triangle
elif(90>A<=180 or 90>B<=180 or 90>C<=180):
print("Obtuse triangle")
else:
print('Not a triangle')
If at least one angle is 90; then it can't be an acute or obtuse triangle
If all sides are less than 90; then it can't be an obtuse triangle
Hense the the if-else flow
Upvotes: 0
Reputation: 251
Your if conditions are incorrect. And you should use elif instead of if without first if. Because a triangle can't be acute and obtuse at the same time.
A = int(input("enter the number of 1 : "))
B = int(input("enter the number of 2 : "))
C = int(input("enter the number of 3 : "))
if A+B+C != 180 or A<0 or A>180 or B<0 or B>180 or C<0 or C>180:
print("NOT TRIANGLE")
elif A<90 and B<90 and C<90:
print("acute angle")
elif (A>90 and A<180) or (B>90 and B<180) or (C>90 and C<180):
print("obtuse angle")
elif A==90 or B==90 or C==90:
print("carpenter's triangle")
else:
print("Wut?")
Upvotes: 0
Reputation: 1275
Hmmm, If I understand you right:
if A+B+C != 180:
#Cannot be a triangle
print("Not triangle, please enter new values")
else:
#We can proceed as its a viable entry
if A < 90 and B < 90 and C < 90:
print("Acute Angle")
elif A == 90 or B == 90 or C == 90:
print("Carpenter's triangle")
elif A > 90 or B > 90 or C > 90:
print("Obtuse angle")
else:
print("Some other scenario we haven't accounted for")
As your logic stands, you are never getting into your print("acute angle") scenario for a valid triangle.
Upvotes: 1