简单Python-3程序中的语法错误

-2 投票
4 回答
1829 浏览
提问于 2025-04-16 02:42

from TurtleWorld import *
import math

bob = Turtle()
print(bob)

draw_circle(turtle, r):
    d = r*2
    c = d*math.pi
    degrees = 360/25
    length = c // 25
    for i in range(25):
        fd(turtle, length)
        rt(turtle, degrees)

draw_circle(bob, 25)

wait_for_user()

问题出在第7行:

draw_circle(turtle, r):

编译器只告诉我有语法错误,并把那行末尾的冒号标红了。
我知道我可能漏掉了什么简单的东西,但我觉得代码看起来没问题。

4 个回答

1

你需要写:

def draw_circle(turtle, r):

定义一个函数

2

在Python中,我们用def这个关键词来定义函数。就像这样:

def draw_circle(turtle, r):
    # ...

撰写回答