If you remove comments and spacing, got it to 31 lines.
Updated code. Now 25 lines without spaces and comments
from random import choice, randint from turtle import Turtle, write, goto, penup, pendown, speed, hideturtle from time import sleep # List of 10 colors colors = ['yellow', 'orange', 'red', 'pink', 'purple', 'blue', 'green', 'brown', 'gray', 'black'] # Hide the turtle and draw the start and finish line hideturtle(), speed('fastest') penup(), goto(-200, 10*30/2), pendown(), goto(-200, 0-270) penup(), goto(200, 10*30/2), pendown(), goto(200, 0-270) class MyTurtle(Turtle): '''Create turtle objects and set properties''' def __init__(self, pos): super().__init__() color = colors.pop(randint(0, len(colors)-1)) if colors else None self.color(color), self.shapesize(2) self.penup() self.goto(-200, (pos*30) - (10*30/2)) # Create a list of turtle objects turtles = list(MyTurtle(i-2.5) for i in range(1, 11)) # Set a variable for accessing turtle objects i = 0 # Setup a while loop racing = True while racing: # Create a random distance to travel and icrease i turtles[i := (i + 1) % len(turtles)].forward(randint(0, 5)) # Track movement of turtle object in list # First to line wins goes to home and writes winner # Sleep for five seconds to see the winner if turtles[i].xcor() >= 200: winner = turtles[i] winner.write(f'winner: turtle {i+1}', font=('system', 25, 'bold')) sleep(5) racing = False
Updated code. Now 25 lines without spaces and comments
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts