画出奥运五环图,代码如下:
import turtle turtle.width(10) turtle.color("blue") turtle.circle(50) turtle.color("black") turtle.penup() turtle.goto(120, 0) turtle.pendown() turtle.circle(50) turtle.color("red") turtle.penup() turtle.goto(240, 0) turtle.pendown() turtle.circle(50) turtle.color("yellow") turtle.penup() turtle.goto(60, -50) turtle.pendown() turtle.circle(50) turtle.color("green") turtle.penup() turtle.goto(180, -50) turtle.pendown() turtle.circle(50)
定义多点坐标_绘出折线_并计算起始点和终点距离
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)
本文为张军原创文章,转载无需和我联系,但请注明来自张军的军军小站,个人博客http://www.zhangjunbk.com