我想创建同心圆。我希望用户在任何指定的半径输入他们想要的圆圈数。我的问题是圈子之间没有相互形成。任何提示都很棒
import turtle
import random
n1 = int(input("How many circles"))
n2 = int(input("Radius?"))
for i in range(n1):
turtle.penup()
turtle.right(50)
turtle.forward(i)
turtle.begin_fill()
turtle.color(random.random(), random.random(), random.random())
turtle.circle(n2)
turtle.end_fill()
turtle.pendown()
turtle.home()
while i in range(n1):
turtle.pendown()
turtle.right(40)
turtle.forward(i)
turtle.begin_fill()
turtle.color(random.random(), random.random(), random.random())
turtle.circle(n2-20)
turtle.end_fill()
turtle.penup()
答案 0 :(得分:0)
import turtle
import random
num = int(input("How many circles? "))
radius = int(input("Radius? "))
# move to starting point - tangent to right edge of largest circle
turtle.forward(radius)
turtle.left(90)
# draw circles, largest to smallest
for circle in range(num, 0, -1): # (num .. 1)
# draw a filled circle
turtle.begin_fill()
turtle.color(random.random(), random.random(), random.random())
turtle.circle(radius * circle / num)
turtle.end_fill()
# shift inward to next circle starting-point
turtle.left(90)
turtle.forward(radius / num)
turtle.right(90)
给出6,120产生