Не знаю как выявить победителя, помогите пожалуйста

ConderKanS

Новичок
Пользователь
Май 18, 2020
4
0
1
Игра черепашьи бега, работает хорошо, но в конце не знаю как сделать так чтобы выводилось какая черепашка пришла первой, какая второй и какая третьей, спасибо

from turtle import *
from random import *

t = Turtle()
t.penup()
t.goto(-100,100)
t.pendown()

t.speed(0)

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,35)
second.pendown()

third=Turtle()
third.shape("turtle")
third.color("yellow")
third.penup()
third.goto(-120,0)
third.pendown()

fourth=Turtle()
fourth.shape("turtle")
fourth.color("green")
fourth.penup()
fourth.goto(-120,-35)
fourth.pendown()

fifth=Turtle()
fifth.shape("turtle")
fifth.color("orange")
fifth.penup()
fifth.goto(-120,-70)
fifth.pendown()

chs = randint(1,10)
sps = ["red", "blue", "yellow", "green", "orange"]

for i in range(0, chs + 1):
chs1 = randint(1,5)
if chs1 == 1:
chs2 = "red"
elif chs1 == 2:
chs2 = "blue"
elif chs1 == 3:
chs2 = "yellow"
elif chs1 == 4:
chs2 = "green"
else:
chs2 = "orange"
bol = Turtle()
bol.shape("turtle")
bol.color(chs2)
bol.penup()
bol.goto(-90+25*i,-120)
bol.pendown()
bol.left(90)

x_first = 0
x_second = 0
x_third = 0
x_fourth = 0
x_fifth = 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_fourth<305) and (x_fifth<305)):

first_step = randint(1,5)
x_first += first_step
first.up()
first.forward(first_step)

second_step = randint(1,5)
x_second += second_step
second.up()
second.forward(second_step)

third_step = randint(1,5)
x_third += third_step
third.up()
third.forward(third_step)

fourth_step = randint(1,5)
x_fourth += fourth_step
fourth.up()
fourth.forward(fourth_step)

fifth_step = randint(1,5)
x_fifth += fifth_step
fifth.up()
fifth.forward(fifth_step)[/CODE]
 

stud_55

Модератор
Команда форума
Модератор
Апр 3, 2020
1 522
672
113
Вот пример:
Python:
from turtle import *
from random import *

t = Turtle()
t.penup()
t.goto(-100, 100)
t.pendown()

t.speed(0)

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,35)
second.pendown()

third=Turtle()
third.shape("turtle")
third.color("yellow")
third.penup()
third.goto(-120,0)
third.pendown()

fourth=Turtle()
fourth.shape("turtle")
fourth.color("green")
fourth.penup()
fourth.goto(-120, -35)
fourth.pendown()

fifth = Turtle()
fifth.shape("turtle")
fifth.color("orange")
fifth.penup()
fifth.goto(-120, -70)
fifth.pendown()

chs = randint(1, 10)
sps = ["red", "blue", "yellow", "green", "orange"]

for i in range(0, chs + 1):
    chs1 = randint(1, 5)
    if chs1 == 1:
        chs2 = "red"
    elif chs1 == 2:
        chs2 = "blue"
    elif chs1 == 3:
        chs2 = "yellow"
    elif chs1 == 4:
        chs2 = "green"
    else:
        chs2 = "orange"

bol = Turtle()
bol.shape("turtle")
bol.color(chs2)
bol.penup()
bol.goto(-90 + 25 * i, -120)
bol.pendown()
bol.left(90)

x_first = 0
x_second = 0
x_third = 0
x_fourth = 0
x_fifth = 0

text = input('Прогноз, какая черепаха победит?')
tex = Turtle()
tex.penup()
tex.goto(-120, 120)
tex.hideturtle()
tex.write('Ты считаешь, что победит ' + text, font = ('Arial', 12, 'bold'))


def move_turtle(num, turtle_):
    step = randint(1, 5)
    num += step
    turtle_.up()
    turtle_.forward(step)
    return num

def place():
    yield from ['Первое место', 'Второе место', 'Третье место']

def is_winner(num, string_num, winners, x):
    if num >= 305 and winners.get(string_num) is None and winners['count'] < 3:
        winners[string_num] = next(x)
        winners['count'] += 1

x = place()

winners = {'count': 0}

while True:
    x_first = move_turtle(x_first, first)
    is_winner(x_first, '1 черепаха', winners, x)
    x_second = move_turtle(x_second, second)
    is_winner(x_second, '2 черепаха', winners, x)
    x_third = move_turtle(x_third, third)
    is_winner(x_third, '3 черепаха', winners, x)
    x_fourth = move_turtle(x_fourth, fourth)
    is_winner(x_fourth, '4 черепаха', winners, x)
    x_fifth = move_turtle(x_fifth, fifth)
    is_winner(x_fifth, '5 черепаха', winners, x)

    if winners['count'] == 3:
        break

del winners['count']
print(winners)
 

Форум IT Специалистов