Измените программу так, чтобы болельщики были разноцветные.
Каждый болеет за любимого участника.
Красные черепахи болеют за красных, синие за синих, желтые за желтых.
Случайным образом определи, за кого болеет каждый болельщик и раскрась черепашку в нужный цвет.
Можно пойти дальше и покрасить каждую черепашку в случайный цвет с палитры.
t.color(red, green, blue)
Подсказка: минимальное значение параметра в RGB палитре это 0, а максимальное это 255
Вот мой код:
import turtle
import random
t = turtle.Turtle()
t.penup()
t.goto(-100,100)
t.pendown()
t.speed(0)
for i in range(0,16):
t.write(i)
t.right(90)
t.forward(200)
t.left(180)
t.forward(200)
t.right(90)
t.forward(20)
for j in range(1, 10):
bol = turtle.Turtle()
bol.shape("turtle")
bol.color('rgb(255, 10, 0)')
bol.penup()
bol.goto(-90+25*j,-120)
bol.pendown()
bol.left(90)
first = turtle.Turtle()
first.shape("turtle")
first.color("red")
first.penup()
first.goto(-120,70)
first.pendown()
second = turtle.Turtle()
second.shape("turtle")
second.color("blue")
second.penup()
second.goto(-120,40)
second.pendown()
second2 = turtle.Turtle()
second2.shape("turtle")
second2.color("yellow")
second2.penup()
second2.goto(-125,10)
second2.pendown()
x_first = 0
x_second = 0
text = input("Прогноз, какая черепаха победит?")
tex = turtle.Turtle()
tex.penup()
tex.goto(-140,-140)
tex.write(" Пользователь считает, что победит: " + text, font = ("Arial", 12, "bold"))
while ((x_first<600) and (x_second<650)):
first_step = random.randint(1,5)
x_first += first_step
first.forward(first_step)
second_step = random.randint(1,5)
x_second += second_step
second.forward(second_step)
second2_step = random.randint(1,5)
x_second += second2_step
second2.forward(second2_step)
begin
var s:=ReadLines('in.txt').ToArray;
var n:=StrToInt(s[0]);
var a:=s[1].ToWords.Select(e->StrToInt(e)).ToArray;
var f:=OpenWrite('out.txt');
Writeln(f,n,' - (кол-во чисел)');
foreach var e in a do Write(f,e,' '); Writeln(f);
Writeln(f,'Среднее значение четных ',
a.Where(x->x.IsEven).Average);
Writeln(f,'Среднее значение нечетных ',
a.Where(x->x.IsOdd).Average);
f.Close
end.
Файлы in.txt и out.txt находятся во вложении.
Содержимое файла out.txt:
15 - (кол-во чисел)
-22 49 33 47 -10 -1 20 -18 2 21 2 -25 21 -47 -36
Среднее значение четных -8.85714285714286
Среднее значение нечетных 12.25