import turtle
import math
#定义多个点坐标
x1,y1 = 100,100
x2,y2 = 100,-100
x3,y3 = -100,-100
x4,y4 = -100,100
#绘制折线
turtle.penup()
turtle.goto(x1,y1)
turtle.pendown()
turtle.goto(x2,y2)
turtle.goto(x3,y3)
turtle.goto(x4,y4)
#计算起始点和终点的距离
distance = math.sqrt( (x1-x4)**2 + (y1-y4)**2 )
turtle.write(distance)
3 【 *** 作】测试+拼接符join
import time
time01 = time.time() #起始时间
a = ""
for i in range(10000):
a += "sxt"time02 = time.time() #终止时刻
print("运算时间: "+str(time02-time01))
time03 = time.time() #起始时间
li = []
for i in range(10000):
li.append("sxt")
a ="".join(li)
time04 = time.time() #终止时刻
print("运算时间: "+str(time04-time03))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)