Пустой список хотя я его заполнял
У меня есть список star_areas, который по началу пустой. Я хотел его заполнить в функции.
Вот функция:
def houses(x, y):
global star_areas
turtle.up()
turtle.goto(x, y)
turtle.down()
h, w = randrange(300, 501, 60), randrange(200, 401, 60)
lst = ('gray', 'Burlywood')
house(x, y, h, w, choice(lst))
star_areas.append((x, x + w, h))
for _ in range(5):
x += w + 1
star_areas.append((x, x + w, h))
h, w = randrange(300, 501, 60), randrange(200, 401, 60) #randrange(500, 701, 60), randrange(200, 401, 60)
house(x, y, h, w, choice(lst))
Вроде она заполняется, но когда я хочу вывести ее содержимое вне функции, ничего не выводится. Но если запринтить список в функции, то все нормально выводится.
Вот весь код:
from random import *
star_areas = []
def house(x, y, height, width, color):
turtle.up()
turtle.goto(x, y)
turtle.down()
turtle.fillcolor(color)
turtle.begin_fill()
turtle.left(90)
turtle.forward(height)
turtle.right(90)
turtle.forward(width)
turtle.right(90)
turtle.forward(height)
turtle.left(90)
turtle.end_fill()
for i in range(x + 10, x + width - 10, 40):
for j in range(y + 10, y + height - 10, 40):
window(i, j, 20, randint(0, 1))
def window(x, y, side, islight_on):
turtle.fillcolor(('black', 'yellow')[islight_on])
turtle.up()
turtle.goto(x, y)
turtle.down()
turtle.begin_fill()
for _ in range(4):
turtle.forward(side)
turtle.left(90)
turtle.end_fill()
#turtle.forward(side / 2)
#turtle.left(90)
#turtle.forward(side)
#turtle.up()
#turtle.goto(x, y)
#turtle.right(90)
#turtle.down()
def houses(x, y):
global star_areas
turtle.up()
turtle.goto(x, y)
turtle.down()
h, w = randrange(300, 501, 60), randrange(200, 401, 60)
lst = ('gray', 'Burlywood')
house(x, y, h, w, choice(lst))
star_areas.append((x, x + w, h))
for _ in range(5):
x += w + 1
star_areas.append((x, x + w, h))
h, w = randrange(300, 501, 60), randrange(200, 401, 60) #randrange(500, 701, 60), randrange(200, 401, 60)
house(x, y, h, w, choice(lst))
#print(star_areas)
def star(x, y, size):
turtle.up()
turtle.goto(x, y)
turtle.down()
turtle.fillcolor('yellow')
turtle.begin_fill()
for _ in range(4):
turtle.forward(size)
turtle.left(90)
turtle.forward(0)
turtle.end_fill()
xcors = []
ycors = []
def stars():
#global xcors, ycors, star_areas
for area in star_areas:
a, b, c = area
while len(xcors) != 10:
x, y = randrange(a, b - 15), randrange(c + 10, 1000)
while checking(x, y) != True:
x, y = randrange(a, b - 15), randrange(c, 550)
xcors.append(x)
ycors.append(y)
star(x, y, randint(13, 15))
def checking(x, y):
global xcors, ycors
if x in xcors or y in ycors:
return False
else:
return True```