Skip to content

Commit f5a1540

Browse files
Akshat Raj AnandAkshat Raj Anand
authored andcommitted
New python Mini Project
1 parent ab7c06b commit f5a1540

File tree

3 files changed

+181
-0
lines changed

3 files changed

+181
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Rock Paper Scissor Game🔥
2+
3+
- In the rock, paper and scissors game our goal is to create a command-line game where a user has the option to choose between rock, paper and scissors and if the user wins the score is added, and at the end when the user finishes the game, the score is shown to the user.
4+
5+
## 📌Rock, Paper and Scissors Game with Python
6+
7+
- To create the Rock, Paper and Scissors game with Python, we need to take the user’s choice and then we need to compare it with the computer choice which is taken using the random module in Python from a list of choices, and if the user wins then the score will increase by 1:
8+
9+
### Code:
10+
11+
import random
12+
13+
choices = ["Rock", "Paper", "Scissor"]
14+
15+
player = False
16+
cpu_score = 0
17+
player_score = 0
18+
19+
while True:
20+
player = input("Enter your choice ").capitalize()
21+
22+
computer = random.choice(choices)
23+
24+
if computer == player:
25+
print("Its tie now...")
26+
27+
elif player == "Rock":
28+
if computer == "Paper":
29+
print("You lose...", computer, "covers", player)
30+
cpu_score += 1
31+
32+
else:
33+
print("You won...", player, "smashes", computer)
34+
player_score += 1
35+
36+
elif player == "Paper":
37+
if computer == "Rock":
38+
print("You won...", player, "covers", computer)
39+
player_score += 1
40+
41+
else:
42+
print("You lose...", computer, "cut", player)
43+
cpu_score += 1
44+
45+
elif player == "Scissor":
46+
if computer == "Paper":
47+
print("You won...", player, "cut", computer)
48+
player_score += 1
49+
50+
else:
51+
print("You lose...", computer, "smashes", player)
52+
cpu_score += 1
53+
54+
elif player == "End":
55+
print("The final scores are ")
56+
print(f"CPU Score {cpu_score}")
57+
print(f"Player Score {player_score}")
58+
break
59+
60+
61+
### Output:
62+
63+
Enter your choice rock
64+
Its tie now...
65+
Enter your choice paper
66+
You won... Paper covers Rock
67+
Enter your choice scissors
68+
You lose... Rock smashes Scissors
69+
Enter your choice end
70+
The final scores are
71+
CPU Score 1
72+
Player Score 1
73+
74+
## 📌Summary
75+
76+
- Creating these types of games will help a beginner to think logically. You can even use this idea to make your own game. In the end, creating these types of programs will help you create your algorithms, which is a very important skill for coding interviews and competitive programming.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import random
2+
3+
randNo = random.randint(1,3)
4+
if randNo == 1:
5+
computer_choose = "r" # if randNo is equal to 1 then it will store 'r' as computer choice
6+
if randNo == 2:
7+
computer_choose = "p" # if randNo is equal to 2 then it will store 'p' as computer choice
8+
if randNo == 3:
9+
computer_choose = "s" # if randNo is equal to 3 then it will store 's' as computer choice
10+
11+
# Defining gameWin function for performing major task for this game.
12+
13+
def gameWin(computer_choose, user_input):
14+
if computer_choose == user_input:
15+
return None
16+
elif computer_choose == "r":
17+
if user_input == "p":
18+
return True
19+
elif user_input == "s":
20+
return False
21+
22+
elif computer_choose == "p":
23+
if user_input == "r":
24+
return False
25+
elif user_input == "s":
26+
return True
27+
28+
elif computer_choose == "s":
29+
if user_input == "r":
30+
return True
31+
elif user_input == "p":
32+
return False
33+
34+
print("Computer Choosed already from Rock('r') or Paper('p') or Scissor('s')")
35+
36+
print("Now your turn to choose")
37+
38+
user_input = input("Choose from Rock('r') or Paper('p') or Scissor('s') ") #taking input from the user
39+
40+
# It shows the user what computer choose from rock, paper or scissor.
41+
print("Computer choosed " + computer_choose)
42+
43+
# It shows the user what he/she choose from rock, paper or scissor.
44+
print("You Choosed " + user_input)
45+
46+
47+
# This block of if-else statement will find out conditon of gameWin function
48+
49+
if gameWin(computer_choose, user_input) == None:
50+
print("It tie now")
51+
52+
elif gameWin(computer_choose, user_input):
53+
print("Congratulations You Won!!!")
54+
55+
else:
56+
print("You Lose!")
57+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import random
2+
3+
choices = ["Rock", "Paper", "Scissor"]
4+
5+
player = False
6+
cpu_score = 0
7+
player_score = 0
8+
9+
while True:
10+
player = input("Enter your choice ").capitalize()
11+
12+
computer = random.choice(choices)
13+
14+
if computer == player:
15+
print("Its tie now...")
16+
17+
elif player == "Rock":
18+
if computer == "Paper":
19+
print("You lose...", computer, "covers", player)
20+
cpu_score += 1
21+
22+
else:
23+
print("You won...", player, "smashes", computer)
24+
player_score += 1
25+
26+
elif player == "Paper":
27+
if computer == "Rock":
28+
print("You won...", player, "covers", computer)
29+
player_score += 1
30+
31+
else:
32+
print("You lose...", computer, "cut", player)
33+
cpu_score += 1
34+
35+
elif player == "Scissor":
36+
if computer == "Paper":
37+
print("You won...", player, "cut", computer)
38+
player_score += 1
39+
40+
else:
41+
print("You lose...", computer, "smashes", player)
42+
cpu_score += 1
43+
44+
elif player == "End":
45+
print("The final scores are ")
46+
print(f"CPU Score {cpu_score}")
47+
print(f"Player Score {player_score}")
48+
break

0 commit comments

Comments
 (0)