任务是写一个可以做三角形的代码(求周长,面积,如果是等边,右等)
我相信我的代码在目标上,但是当数字不形成三角形时,它不会像它应该呈现的那样呈现错误。任何帮助将不胜感激。
import math
A = int (input ("Type in your first integer that you would like to test:"))
print ("Your first integer to be tested is:", A)
B = int (input ("Type in your second integer that you would like to test:"))
print ("Your second integer to be tested is:", B)
C = int (input ("Type in your third integer that you would like to test:"))
print ("Your third integer to be tested is:", C)
if (A > B):
largest = A
else:
largest = B
if (C > largest):
largest = C
print ("The largest number is:", largest)
if A<=0 or B<=0 or C<=0:
print("The numbers don't form a triangle")
else:
print("The Triangle's Perimeter is:")
print(int(A+B+C))
print("The semiperimeter is:")
print(int((A+B+C)/2))
print("The Area of the triangle is:")
print (int (math.sqrt((A+B+C)/2)*(((A+B+C)/2)-A)*(((A+B+C)/2)-B)*(((A+B+C)/2)-C)))
if int(A != B and A != C and B != C):
print("The triangle is a scalene")
else:
print ("The triangle is not a scalene")
if int(A == B and B == A or A == C and C == A or C == B and B == C):
print ("The triangle is an isosceles")
else:
print ("The triangle is not an isosceles")
if int(A == B == C):
print("The triangle is an equilateral")
else:
print("The triangle is not an equilateral")
if int(C*C == A*A + B*B):
print("The triangle is a right triangle")
else:
print("The triangle is not a right triangle")