Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 76533a9

Browse files
Merge pull request avinashkranjan#1115 from anumshka/TurtleRacing
Turtle Racing
2 parents 06c95fe + 2040881 commit 76533a9

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

‎TurtleRace/TurtleRace.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import turtle as t
2+
import random
3+
import time
4+
5+
scr = t.Screen()
6+
scr.setup(width=500, height=500)
7+
UserInput = scr.textinput(title="Play luck",
8+
prompt="Who would win in your opinion??Enter your lucky color from rainbow")
9+
# declaring a list of colors
10+
ColorList = ["Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"]
11+
RaceRunning = False
12+
Runners = []
13+
pos = -100
14+
# for each and every turtle
15+
for i in range(0, 7):
16+
NewTurtle = t.Turtle()
17+
NewTurtle.shape("turtle")
18+
NewTurtle.penup()
19+
NewTurtle.color(ColorList[i])
20+
NewTurtle.goto(x=-250, y=pos)
21+
pos += 50
22+
Runners.append(NewTurtle)
23+
if UserInput:
24+
RaceRunning = True
25+
# till the game is running
26+
while RaceRunning :
27+
for runner in Runners:
28+
if runner.xcor() > 230:
29+
winner = runner.pencolor()
30+
RaceRunning = False
31+
show = t.Turtle()
32+
show.hideturtle()
33+
show.penup()
34+
show.goto(-200, -150)
35+
show.color("red")
36+
if winner.lower() == UserInput.lower():
37+
print("Your turtle won!")
38+
show.write("Your turtle won!")
39+
else:
40+
print(f"Your turtle lost, the winner is {winner} turtle!")
41+
show.write(f"Your turtle lost, the winner is {winner} turtle!")
42+
runner.forward(random.randint(0, 10))
43+
scr.exitonclick()

‎TurtleRace/output.png

13.4 KB
Loading[フレーム]

‎TurtleRace/readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Package/Script Name
2+
3+
TurtleRace.py : to make the turtles move
4+
5+
## Setup instructions
6+
7+
python file.py
8+
9+
## Detailed explanation of script, if needed
10+
11+
The user will bet on a turtle to win and a race would be hosted to see who wins.
12+
13+
## Output
14+
15+
![](output.png)
16+
17+
## Author(s)
18+
19+
-[Anushka Pathak](https://github.com/anumshka)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /