1.
2.
3.
import math def triangle_test1(): a1=float(input("第一点横坐标:")) a2=float(input("第一点纵坐标:")) b1 = float(input("第2点横坐标:")) b2 = float(input("第2点纵坐标:")) c1 = float(input("第3点横坐标:")) c2 = float(input("第3点纵坐标:")) AB=abs(math.sqrt((a1 - b1) ** 2 + (a2 - b2) ** 2)) AC=abs(math.sqrt((a1 - c1) ** 2 + (a2 - c2) ** 2)) BC=abs(math.sqrt((b1 - c1) ** 2 + (b2 - c2) ** 2)) cosB=-(AC ** 2 - AB ** 2 - BC **2) / (2 * AB * BC) cosA=-(BC**2-AC**2-AB**2)/(2*AB*AC) cosC=-(AB**2-AC**2-BC**2)/(2*AC*BC) aa=math.acos(cosA) * 180 / math.pi bb=math.acos(cosB) * 180 / math.pi cc=math.acos(cosC) * 180 / math.pi if aa+bb+cc==180: area = 0.5*(AB*math.sin(bb/180*math.pi))*(AB*cosB+AC*cosC) print("面积是",area) else: print("坐标有误") triangle_test1()
4.
5.
def line(): import turtle a=[] c=0 num=int(input("输入点数:")) for c in range(2*num): a.append(input("输入坐标:")) print(a,len(a)) i,j=0,0 for i in range(0,num+2,2): turtle.penup() turtle.goto(float(a[i]), float(a[i + 1])) for j in range(i+2,2*num-1,2): turtle.pendown() turtle.goto(float(a[j]),float(a[j+1])) turtle.penup() turtle.goto(float(a[i]),float(a[i+1])) turtle.done() line()