bài 26
-Xác định bài toán
input: 3 điểm A(x1;x2), B(x2;y2) và C(x3;y3)
output:kiểm tra A B C có phải đỉnh của tam giác không
+ Có thì tính và đưa ra diện tích tam giác
+ Không thì in ra "KHUM"
-Thuật toán: Tính độ dài 3 cạnh tam giác
dAB=sqrt((xB-xA)^2 + (yB-yA)^2)
dAC=sqrt((xC-xA)^2 + (yC-yA)^2)
dBC=sqrt((xC-xB)^2 + (yC-yB)^2)
-Code
from math import sqrt
from math import pow
x1=int(input())
y1=int(input())
x2=int(input())
y2=int(input())
x3=int(input())
y3=int(input())
ab=sqrt(pow(x2-x1,2)+ pow(y2-y1,2))
ca=sqrt(pow(x1-x3,2)+ pow(y1-y3,2))
bc=sqrt(pow(x3-x2,2)+ pow(y3-y2,2))
if (ab+bc>ca) and(bc+ca>ab) and (ca+ ab>bc):
p=(ab+bc+ca)/2.0
s=sqrt(p*(p-ab)*(p-bc)*(p-ca))
print("{:.3f}".format(s))
else:
print("KHUM")
-Test
2
5
6
5
7
3
kq: 4.000
2
0
6
0
7
0
kq:KHUM