top of page

Turtle Race!


Guess which turtle will win the race!
Put in your bets! Wait, sorry...that's illegal, please don't actually bet real money on this...

P.S. Code is below
ree
from turtle import Turtle, Screen
import random

screen = Screen()
screen.setup(width=500,height=400)
user_bet = screen.textinput(title="Make your bet", prompt = "Which turtle do you think will win the race? Enter the turtle color: ")
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
y_positions = [-100, -60, -20, 20, 60, 100]
all_turtles = []


is_race_on = False


for turtle_index in range(0,6):
  new_turtle = Turtle(shape = "turtle")
  new_turtle.penup()
  new_turtle.color(colors[turtle_index])
  new_turtle.goto(x=-230, y = y_positions[turtle_index])
  all_turtles.append(new_turtle)

if user_bet:
  is_race_on = True

while is_race_on:

  for turtle in all_turtles:
    if turtle.xcor() > 230:
      winning_color = turtle.pencolor()
      if winning_color == user_bet:
        print(f"You have won! {winning_color.title()} turtle has won the race!")
      else:
        print(f"You lose! {winning_color.title()} turtle has won the race!")

      is_race_on = False

    rand_distance = random.randint(0,10)
    turtle.forward(rand_distance)

screen.exitonclick()


Recent Posts

See All
Python Practices

Had some crazy time trying to do some of these exercises. Can't seem to solve the Pascal's Triangle Question for Day 2. (most probably...

 
 
 

Comments


Subscribe to me for updates on my life!

Thanks for submitting!

  • Instagram

©2021 by Sloppy Joel's. Proudly created with Wix.com

bottom of page