방금 파이썬을 사용하는 법을 배우기 시작했으며, 내 프로그램에 어떤 문제가 있는지 확인할 수 없는지 묻습니다. 잘못된 포럼 일 경우 직접 알려주십시오. 나에게 맞는 것. 3 개의 길이가 모두 입력 될 때 삼각형의 3 개의 각을 제공하도록 설계된 계산기입니다. 그것은 코딩의 측면에서 작동하는 것 같지만 3 가지 각도는 동일하지 않아야합니다. 아래 코드를 실행하면 내가 말하는 것을 볼 수 있습니다. 또한 삼각형의 유형을 해결 abit dodgy하지만 이것은 내 자신의 문제를 면밀히 검토 할 때 내 자신의 문제를 해결할 것이라고 확신합니다.수식 오류를 확인할 수 없습니다
import math
#degrees = (180/pi).radians (python maths works in radians) & radians = (pi/180).degrees
print("Welcome to the tri-angle calculator, please ensure that all 3 length inputs form a triangle otherwise program will not function. They must also be converted to the same units of length")
a = int(input("Insert first length of triangle in degrees: "))
b = int(input("Insert second length of triangle in degrees: "))
c = int(input("Insert third length of triangle in degrees: "))
#length inputs
A = math.acos(((b ** 2) + (c ** 2) - (a ** 2))/(2 * b * c))
B = math.acos(((a ** 2) + (c ** 2) - (b ** 2))/(2 * a * c))
C = math.acos(((a ** 2) + (b ** 2) - (c ** 2))/(2 * a * b))
#working out all 3 angles of triangles
if(a == c and b == c):
type = "Equilateral Triangle"
elif(math.cos(A) == 0 or math.cos(B) == 0 or math.cos(C) == 0):
type = "Right Angle Triangle"
elif((a == b and c != b) or (b == c and c == a) or (c == a and c != b)):
type = "Isoceles Triangle"
elif(a != b and b != c and c != a and A < (0.5 * math.pi) and B < (0.5 * math.pi) and C < (0.5 * math.pi)):
type = "Acute Triangle"
else:
type = "Obtuse Triangle"
#Working out the triangle type
print("The order of which the angles are shown in are opposite to the length inputted:")
print("Angle A - " + str((180/math.pi) * A))
print("Angle B - " + str((180/math.pi) * A))
print("Angle C - " + str((180/math.pi) * A))
print("And it's a " + type)
#Printing Results
exit()
봐 (마지막 5 줄) – user3080953
참고 :'a','b','c' 숫자가 실제로 삼각형이 될 수 있는지 확인하지 않습니다. 또한 길이는도 단위로 측정되지 않습니다. 하하하, 좋은 사람 @ user3080953! – CristiFati
코드 블록이 그 블록이 아닌 블록 뒤에 무엇을하는지에 대한 주석을 넣는 것은 매우 혼란 스럽습니다. – Barmar