【发布时间】:2020-04-05 21:27:17
【问题描述】:
我试图制作一种复杂的参数化绘图仪,但这并不重要。重要的是我的程序应该使用 Turtle 图形绘制一个圆圈,当我放下笔时,“turtle.pd()”行出现语法错误。我不知道是怎么回事。你们能帮帮我吗?我的程序在下面。
import turtle, math, cmath
def f(x): return math.e ** (1j * x) # Use Python code to define f(x) as the return value; don't forget the math and cmath modules are imported
precision = 25 # This program will draw points every (1 / precision) units
def draw(x):
value = f(x)
try:
turtle.xcor = value.real * 25 + 100
turtle.ycor = value.imag * 25 + 100
turtle.pd() # Syntax error here
turtle.forward(1)
turtle.pu()
draw(0)
num = 0
while True:
num += 1
draw(num)
draw(-num)
【问题讨论】:
-
try需要except。一般来说,如果您在某个意外的地方收到SyntaxError,请查看上一行/块以查看您是否忘记关闭某些内容,例如)或在本例中为except。 -
不能解决问题
-
“不能解决问题”不是一个有用的回答。请阅读How to Ask。您对代码做了什么确切的更改?
-
为什么
try会出现在首位?
标签: python python-3.x turtle-graphics python-turtle