From turtle import * from random import *
t = Turtle()
t.penup()
t.goto(-100,100)
t.pendown()
t.speed(100)
#поле
for i in range(0,15):
t.write(i)
t.right(90)
t.forward(200)
#возврат
t.left(180)
t.forward(200)
t.right(90)
t.forward(20)
first=Turtle()
first.shape("turtle")
first.color("red")
first.penup()
first.goto(-120,70)
first.pendown()
second=Turtle()
second.shape("turtle")
second.color("blue")
second.penup()
second.goto(-120,40)
second.pendown()
third=Turtle()
third.shape("turtle")
third.color("yellow")
third.penup()
third.goto(-120,-20)
third.pendown()
four=Turtle()
four.shape("turtle")
four.color("green")
four.penup()
four.goto(-120,-50)
four.pendown()
five=Turtle()
five.shape("turtle")
five.color("purple")
five.penup()
five.goto(-120,-80)
five.pendown()
#зрители
bolCount = randint(1,10)
for i in range(0, bolCount):
bol = Turtle()
bol.shape("turtle")
bol.color(randint(0,255),randint(0,255),randint(0,255))
bol.penup()
bol.goto(-90+25*i, -120)
bol.pendown()
bol.left(90)
x_first=0
x_second=0
x_third = 0
x_four = 0
x_five = 0
text = input('Прогноз, какая черепаха победит?')
tex = Turtle()
tex.penup()
tex.goto(-120,120)
tex.hideturtle()
tex.write('Ты считаешь, что победит ' + text, font = ('Arial', 12, 'bold'))
while ((x_first<305) and (x_second<305) and (x_third<305) and (x_four<305) and x_five<305):
first_step = randint(1,5)
x_first += first_step
first.forward(first_step)
second_step = randint(1,5)
x_second += second_step
second.forward(second_step)
third_step = randint(1,5)
x_third += third_step
third.forward(third_step)
four_step = randint(1,5)
x_four += four_step
four.forward(four_step)
five_step = randint(1,5)
x_five += five_step
five.forward(five_step)
по этому коду надо выполнить задание:
С консоли мы можем угадать, какая черепашка победит, а с программы мы можем это однозначно определить!
Давай по завершению гонки выводить в консоль и на экран какая черешка победила.
язык python
// PascalABC.NET 3.1, сборка 1198 от 11.03.2016
begin
var a:=ArrRandom(ReadInteger('n='),0,2); a.Println;
a.Sorted.Println
end.
Тестовое решение:
n= 15
1 2 0 2 2 0 2 0 2 0 0 1 0 0 2
0 0 0 0 0 0 0 1 1 2 2 2 2 2 2
2. Но, поскольку считается, что школьникам больше заняться нечем, их заставляют писать примерно в таком стиле (и время займет, и ощибок понаделают):
// PascalABC.NET 3.1, сборка 1198 от 11.03.2016
const
nn=100;
var
i,j,n,t:integer;
a:array[1..nn] of integer;
begin
Write('n='); Read(n);
Randomize;
for i:=1 to n do begin
a[i]:=Random(3);
Write(a[i],' ')
end;
Writeln;
for i:=1 to n-1 do
for j:=1 to n-1 do
if a[j]>a[j+1] then begin
t:=a[j]; a[j]:=a[j+1]; a[j+1]:=t
end;
for i:=1 to n do Write(a[i],' ');
Writeln;
end.
Тестовое решение:
n=15
0 1 1 0 2 1 0 2 1 2 1 0 0 2 0
0 0 0 0 0 0 1 1 1 1 1 2 2 2 2