在python中使用变量重复模式

时间:2014-10-18 15:15:22

标签: python turtle-graphics

我正在尝试在Python中制作一个重复模式程序,询问您希望重复形状有多少边,应该重复多少次以及背景和形状填充的颜色。它应该在转动之前绘制形状360除以边的数量。然而,它不断在现场重复。我的代码如下。

from turtle import*

bgColor = input("What colour background do you want?:  ")
fillColor = input("What colour shape fill do you want?:  ")
numberOfSides = int(input("How many sides?:  "))
rotationsWanted = int(input("How many rotations?:  "))
rotationsCompleted = 0

def drawshape():
    fillcolor(fillColor)
    bgcolor(bgColor)
    begin_fill()
    while (rotationsCompleted < rotationsWanted):

        for x in range(numberOfSides):

            forward (100)
            right(360/numberOfSides)

        end_fill()

drawshape()
right(360/rotationsWanted)
rotationsCompleted = rotationsCompleted + 1

1 个答案:

答案 0 :(得分:0)

尝试修改while - 循环

rotationsCompleted = 0
while (rotationsCompleted < rotationsWanted):
    rotationsCompleted = rotationsCompleted + 1

end_fill()之后你应该转到另一个位置,可能会使用goto(100, 100)在不同的位置绘制下一个形状。