【发布时间】:2021-05-11 13:55:55
【问题描述】:
所以我需要我的乌龟在用户点击屏幕的位置绘制任何正多边形 并打印出他们绘制的多边形的总长度。
import turtle
t=turtle.Turtle()
tlength=0
def figure(num, length):
for i in range(num):
t.forward(length)
t.left(360/num)
global tlength
tlength = tlength+length
def drawit(x, y):
shape = int(turtle.textinput("","What Shape?"))
if shape!="0":
length = int(turtle.textinput("","The length of side? "))
t.penup()
t.goto(x, y)
t.pendown()
figure(shape, length)
t.write("total drawn length=", tlength)
s = turtle.Screen()
s.onscreenclick(drawit)
这是我到目前为止所拥有的......它运作良好,只是它不会打印出总长度。有什么建议吗?
【问题讨论】:
-
你能修正你的代码格式吗?否则很难理解您的代码。
-
你为什么不用
t.xcor()?
标签: python python-3.x turtle-graphics python-turtle