python - 为什么“turtle.pd”会在我的 Python 代码中产生语法错误?
问题描述
我试图制作一种复杂的参数化绘图仪,但这并不重要。重要的是我的程序应该使用 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)
解决方案
我会补充
except [errortype]:
pass
块之后try
。将 [errortype] 替换为您希望通过 try 块减少的错误。我看不出该块内可能会引发什么错误,您可能只是写
turtle.xcor = value.real * 25 + 100
turtle.ycor = value.imag * 25 + 100
并一起删除 try 块。
推荐阅读
- java - 在这种特定情况下,如何阻止 Eclipse 缩进额外的空格?
- python - 如何使用登录的用户名在 Python Django 帖子上添加评论?
- powershell - 在 powershell 中转义 $
- ag-grid - 以编程方式删除所有分组和过滤的简单方法
- linux - while循环比较文件
- python - 当我尝试使用 arff.dump() 将 pandas DataFrame 文件保存到 arff 时,为什么会显示错误?
- python - Plotly 密度热图格式化色阶和悬停文本
- python - Python Requests-HTML - 找不到特定数据
- c# - TabControl 不显示基于视图模型类型的内容
- c - C中是否有一个函数可以取变量的最大整数值?