Skip to content

Commit 6926c7d

Browse files
author
Mudit Choudhary
committed
Update file name
1 parent 312bee2 commit 6926c7d

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Rock Paper Scissor Game
2+
### About the Game :-
3+
- It is a game which we all had played in our childhood.
4+
- It is terminal based game.
5+
- It is single player only i.e. you play with computer.
6+
7+
### How to play?
8+
- You get 10 chances.
9+
- Type **r** to choose **Rock**, **p** to choose **Paper**, **s** to choose **Scissor**.
10+
- After game end whomever score is high will win the game.
11+
12+
### Requirements
13+
- Your computer should have Python 3.
14+
- If your computer don't have Python you can download it from google.
15+
16+
### Screenshot of the game
17+
! [Game Image 1] (game_img1.png)
18+
! [Game Image 2] (game_img2.png)
17.1 KB
Loading
17.9 KB
Loading
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import random
2+
3+
4+
def rock_paper_scissor(userPoint, comPoint, chances):
5+
# This while loop continue to till chances is leaser than
6+
while(chances < 10):
7+
randomChoice = random.choice(lst)
8+
userGuess = str(input("Rock, Paper, scissors:\n"))
9+
# Computer wins condition
10+
if userGuess.lower() == "r" and randomChoice == "paper":
11+
print(f"Computer win!\n{'-'*46}\n")
12+
comPoint += 1
13+
chances += 1
14+
elif userGuess.lower() == "p" and randomChoice == "scissors":
15+
print(f"Computer win!\n{'-'*46}\n")
16+
comPoint += 1
17+
chances += 1
18+
elif userGuess.lower() == "s" and randomChoice == "rock":
19+
print(f"Computer win!\n{'-'*46}\n")
20+
comPoint += 1
21+
chances += 1
22+
# User wins condition
23+
elif randomChoice == "rock" and userGuess.lower() == "p":
24+
print(f"You win!\n{'-'*46}\n")
25+
userPoint += 1
26+
chances += 1
27+
elif randomChoice == "paper" and userGuess.lower() == "s":
28+
print(f"You win!\n{'-'*46}\n")
29+
userPoint += 1
30+
chances += 1
31+
elif randomChoice == "scissors" and userGuess.lower() == "r":
32+
print(f"You win!\n{'-'*46}\n")
33+
userPoint += 1
34+
chances += 1
35+
# Draw situation
36+
elif (randomChoice == "rock" and userGuess == "r") or (randomChoice == "paper" and userGuess == "p") or (randomChoice == "scissors" and userGuess == "s"):
37+
print(f"It's a tie!\n{'-'*46}\n")
38+
chances += 1
39+
40+
if userPoint > comPoint:
41+
print(
42+
f"#. User Point is: {userPoint}\n#. Computer Point is: {comPoint}\n")
43+
print(f"You won!! this game.")
44+
elif comPoint > userPoint:
45+
print(
46+
f"#. User Point is: {userPoint}\n#. Computer Point is: {comPoint}\n")
47+
print(f"Computer won!! this game.\n")
48+
else:
49+
print(
50+
f"#. User Point is: {userPoint}\n#. Computer Point is: {comPoint}\n")
51+
print("#. It's tie!")
52+
53+
54+
if __name__ == "__main__":
55+
# This loop is for if user wants to play again or wants to exit the game
56+
while(True):
57+
print("1. Press 'r' for rock\n2. Press 'p' for paper\n3. Press 's' forscissors\n")
58+
lst = ["rock", "paper", "scissors"]
59+
chances = 0
60+
comPoint = 0
61+
userPoint = 0
62+
rock_paper_scissor(userPoint, comPoint, chances)
63+
64+
ask = input("Press any key to continue and e to exit:\n")
65+
if ask.lower() == 'e':
66+
break

0 commit comments

Comments
 (0)