"""Import Statements"""fromturtleimportTurtle,Screenimportrandom"""Variables"""colors=["purple","blue","green","yellow","orange","red"]y_position=[-140,-80,-20,40,100,150,]is_race_on=Trueall_turtles=[]"""Screen setup"""screen=Screen()screen.setup(width=500,height=400)user_bet=screen.textinput(title="Make your bet",prompt="Which turtle will win the race? Pick a color (purple, blue,""green, yellow, orange, red)")"""Objects"""forturtle_indexinrange(0,6):new_turtle=Turtle(shape="turtle")new_turtle.color(colors[turtle_index])new_turtle.penup()new_turtle.goto(x=-225,y=y_position[turtle_index])all_turtles.append(new_turtle)ifuser_bet:is_race_on=Truewhileis_race_on:forturtleinall_turtles:ifturtle.xcor()>217:is_race_on=Falsewinning_color=turtle.pencolor()ifwinning_color==user_bet:print(f"Congratulations, your turtle {winning_color} has won")else:print(f"The winning turtle is {winning_color}, better luck next time")rand_distance=random.randint(0,10)turtle.forward(rand_distance)"""Keep screen open until clicked"""screen.exitonclick()
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)