Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中方形螺旋的边(海龟图形)_Python_Python 3.x_Turtle Graphics - Fatal编程技术网

Python中方形螺旋的边(海龟图形)

Python中方形螺旋的边(海龟图形),python,python-3.x,turtle-graphics,Python,Python 3.x,Turtle Graphics,我创建了一个程序,它使用Turtle图形在Python中生成一个方形螺旋 我有点不确定的是螺旋的两边 我目前的课程内容是: from turtle import * startLength = int(input("Please enter the length of first side: ")) decrement = int(input("Please enter the change in length of side: ")) for i in range (3,8): sta

我创建了一个程序,它使用Turtle图形在Python中生成一个方形螺旋

我有点不确定的是螺旋的两边

我目前的课程内容是:

from turtle import *
startLength = int(input("Please enter the length of first side: "))
decrement = int(input("Please enter the change in length of side: "))
for i in range (3,8):
    startLength = startLength - decrement
    forward(startLength)
    left(90)
当我可以提示用户输入如下所示的边数时,效果会更好:

from turtle import *
startLength = int(input("Please enter the length of first side: "))
decrement = int(input("Please enter the change in length of side: "))
sideNum = int(input("Please enter the number of sides: "))
for i in range (sideNum):
    startLength = startLength - decrement
    forward(startLength)
    left(90)
但我只能要求用户输入起始长度和减量


如何创建具有正确边数的螺旋,而不要求用户输入边数

您可以检查线路的长度,当线路太小时停止,如:

from turtle import *
startLength = int(input("Please enter the length of first side: "))
decrement = int(input("Please enter the change in length of side: "))
while startLength > decrement:
    forward(startLength)
    left(90)
    startLength = startLength - decrement
forward(startLength)
最后一个
向前(startLength)
是添加一个小的剩余位,以便螺旋线在中心结束。另外,我在绘图后放置
startedength=startedength-减量
,以便第一行的长度
startedength