مشروع سباق السلاحف

import random
from turtle import Turtle,Screen

shasha=Screen()
shasha.setup(height=600,width=1000)
shasha.title(’ :turtle::turtle::turtle: سباق السلاحف ')

def race():

colors=('red','green','blue')
turtles_list=[Turtle() for _ in colors]
y_cor_list=[-270,0,270]

for i, turtle_name in enumerate(turtles_list):
    turtle_name.color(colors[i])
    turtle_name.shape('turtle')
    turtle_name.shapesize(5,5,8)
    turtle_name.penup()
    turtle_name.lt(180)
    y_cor=random.choice(y_cor_list)
    turtle_name.goto(x=495,y=y_cor)
    y_cor_list.remove(y_cor)

def user_choice():

    choice=str(shasha.textinput('! انتبه','اختر لون السلحفاة (زرقاء ، خضراء، حمراء)'))
    match choice.lower():
        case 'red' | 'حمراء':
            return 'red'
        case 'green' | 'خضراء':
            return 'green'
        case 'blue' |'زرقاء' :
            return 'blue'
        case _:
            print('Invalid input!')

choice=user_choice()

race_on=True
winner=None
while race_on:
    for turtle_name in turtles_list:
        if -495 >=turtle_name.xcor() :
            race_on=False
            winner=turtle_name.pencolor()

        else:
            turtle_name.fd(random.randint(1,3))
    
    t=Turtle()
    t.ht()
    t.color('black')
    t.goto(x=0,y=30)

    if winner:
        if choice==winner:
            shasha.bgcolor('lightgreen')
            t.write('مبارك الفوز',
                font=('arial',40,'bold'),
                align='center')
        else:
            shasha.bgcolor('red2')
            t.write('حظ عاثر ، حاول مرة أخرى',
                font=('arial',40,'bold'),
                align='center')
            
        t.color('lightslategrey')
        t.goto(x=0,y=-30)
        t.write('انقر فى أى مكان للخروج',
            font=('arial',40,'bold'),
            align='center')
        shasha.exitonclick()


race()