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 2563b8f

Browse files
committed
files added
1 parent bd9f3c2 commit 2563b8f

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

‎TurtleRace/TurtleRace.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import turtle as t
2+
import random
3+
4+
scr = t.Screen()
5+
scr.setup(width=500, height=500)
6+
UserInput = scr.textinput(title="Play luck",
7+
prompt="Who would win in your opinion??Enter your lucky color from rainbow")
8+
# declaring a list of colors
9+
ColorList = ["Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"]
10+
RaceRunning = False
11+
Runners = []
12+
pos = -100
13+
# for each and every turtle
14+
for i in range(0, 7):
15+
NewTurtle = t.Turtle()
16+
NewTurtle.shape("turtle")
17+
NewTurtle.penup()
18+
NewTurtle.color(ColorList[i])
19+
NewTurtle.goto(x=-250, y=pos)
20+
pos += 50
21+
Runners.append(NewTurtle)
22+
if UserInput:
23+
RaceRunning = True
24+
# till the game is running
25+
while RaceRunning :
26+
for runner in Runners:
27+
if runner.xcor() > 230:
28+
winner = runner.pencolor()
29+
RaceRunning = False
30+
if winner == UserInput:
31+
print("Your turtle won!")
32+
else:
33+
print(f"Your turtle lost, the winner is {winner} turtle!")
34+
runner.forward(random.randint(0, 10))
35+
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 によって変換されたページ (->オリジナル) /