如何在 python 上循环以下函数?

问题描述 投票:0回答:0

我正在为一个类创建一个代码。该代码基本上要求用户输入一个整数和一种颜色来制作多边形。多边形完成后,代码再次询问用户是否要重复该过程。这是我卡住的地方,我不确定应该使用哪个循环。如果用户输入“是”,我希望代码重复与之前相同的过程,否则就打印完成。

到目前为止这是我的代码:

#Total No. of sides of the polygon to be drawn 
side = int(input("Side numbers for the polygon: "))
#Polygon color 
x = input("Enter the color of the polygon: ")

import turtle
turtle.fillcolor(x)
turtle.fillcolor()
"x"
turtle.begin_fill() 
for x in range(side):
  turtle.forward(100)
  turtle.right(360/side)
turtle.end_fill()

another = input("Do you want to draw another polygon: ")
while True:
  if another==("no"):
    print("It's done")
else:
  #Total No. of sides of the polygon to be drawn 
  side = int(input("Side numbers for the polygon: "))
  #Polygon color 
  x = input("Enter the color of the polygon: ")
  import turtle
  turtle.fillcolor(x)
  turtle.fillcolor()
  "x"
  turtle.begin_fill() 
  for x in range(side):
    turtle.forward(100)
    turtle.right(360/side)
  turtle.end_fill()
  turtle.hideturtle()
  turtle.done()
python computer-science
© www.soinside.com 2019 - 2024. All rights reserved.