会标红1无效的十进制
import turtle
def drawSnake (rad, angle, len, neckrad)
for i in range (len):
turtle.circle (rad, angle) turtle.circle (-rad, angle)
turtle.circle (rad, angle/2) turtle.fd (rad)
turtle.circle (neckrad+1, 180)
turtle.fd(rad*2/3)
def main () :
turtle. setup (1300, 800,0,0)
pythonsize = 30
turtle.pensize (pythonsize)
turtle.pencolor ("blue")
turtle.seth (-40)
drawSnake (40,80,5 ,pythonsize/2)
main ()
turtle.circle
这是弧度,不是角度
180是pi
参考GPT和自己的思路:
在函数定义中,缺少了一个冒号符号,应该在第二行末尾添加一个冒号。同时,在调用turtle.circle函数时,第一个参数应该是一个数字,不能包含逗号。因此,修改后的代码应该如下所示:
import turtle
def drawSnake(rad, angle, len, neckrad):
for i in range(len):
turtle.circle(rad, angle)
turtle.circle(-rad, angle)
turtle.circle(rad, angle/2)
turtle.fd(rad)
turtle.circle(neckrad+1, 180)
turtle.fd(rad*2/3)
def main():
turtle.setup(1300, 800, 0, 0)
pythonsize = 30
turtle.pensize(pythonsize)
turtle.pencolor("blue")
turtle.seth(-40)
drawSnake(40, 80, 5, pythonsize/2)
main()
这样就可以避免提示无效的十进制的错误了。