我正在尝试编写一个绘制螺旋图的 Python 乌龟程序,但我不断收到此错误:
Traceback (most recent call last):
File "C:\Users\matt\Downloads\spirograph.py", line 36, in <module>
main()
File "C:\Users\matt\Downloads\spirograph.py", line 16, in main
spirograph(R,r,p,x,y)
File "C:\Users\matt\Downloads\spirograph.py", line 27, in spirograph
spirograph(p-1, x,y)
TypeError: spirograph() missing 2 required positional arguments: 'x' and 'y'
>>>
这是代码:
from turtle import *
from math import *
def main():
p= int(input("enter p"))
R=100
r=4
t=2*pi
x= (R-r)*cos(t)-(r+p)*cos((R-r)/r*t)
y= (R-r)*sin(t)-(r+p)*sin((R-r)/r*t)
spirograph(R,r,p,x,y)
def spirograph(R,r,p,x,y):
R=100
r=4
t=2*pi
x= (R-r)*cos(t)-(r+p)*cos((R-r)/r*t)
y= (R-r)*sin(t)-(r+p)*sin((R-r)/r*t)
while p<100 and p>10:
goto(x,y)
spirograph(p-1, x,y)
if p<10 or p>100:
print("invalid p value, enter value between 10 nd 100")
input("hit enter to quite")
bye()
main()
我知道这可能有一个简单的解决方案,但我真的不知道我做错了什么,这是我计算机科学 1 课上的一个练习,我不知道如何解决这个错误。