在输入变量之前就会运行for循环,出现turtle界面

#在输入变量前就会运行for循环,出现小乌龟,而不是像预想的那样,实现自己控制气球的数量

import turtle as t
import random
import time

t.speed(0)

t.colormode(255)

a = int(input('你想要多少个气球啊'))

for i in range(a):
red = random.randint(0,255)
green = random.randint(0,255)
blue = random.randint(0,255)

x = random.randint(-220,220)
y = random.randint(-100,220)

t.penup()
t.goto(x,y)
t.pendown()

t.color(red, green, blue)
t.begin_fill()
t.circle(30)
t.end_fill()

t.right(90)
t.forward(30)
t.left(90)

t.hideturtle()

time.sleep(1)#在输入前就会运行循环

import turtle as t
import random
import time

t.speed(0)

t.colormode(255)

a = int(input('你想要多少个气球啊'))

for i in range(a):
red = random.randint(0,255)
green = random.randint(0,255)
blue = random.randint(0,255)

x = random.randint(-220,220)
y = random.randint(-100,220)

t.penup()
t.goto(x,y)
t.pendown()

t.color(red, green, blue)
t.begin_fill()
t.circle(30)
t.end_fill()

t.right(90)
t.forward(30)
t.left(90)

t.hideturtle()

time.sleep(1)

你好,你检查一下是不是代码缩进有问题,我这里能正常运行,你试试我发的代码

有帮助请采纳,有问题继续交流,你的采纳是对我回答的最大的肯定和动力

img

import turtle as t
import random
import time

t.speed(0)

t.colormode(255)

a = int(input('你想要多少个气球啊'))

for i in range(a):
    red = random.randint(0, 255)
    green = random.randint(0, 255)
    blue = random.randint(0, 255)

    x = random.randint(-220, 220)
    y = random.randint(-100, 220)

    t.penup()
    t.goto(x, y)
    t.pendown()

    t.color(red, green, blue)
    t.begin_fill()
    t.circle(30)
    t.end_fill()

    t.right(90)
    t.forward(30)
    t.left(90)

    t.hideturtle()
    time.sleep(1)  # 在输入前就会运行循环