Skip to content

Commit 0378014

Browse files
Merge pull request #2869 from DEVANSH-GAJJAR/adding-rock-paper-scissors
Adding rock paper scissors
2 parents 16a571a + 27e1df1 commit 0378014

File tree

3 files changed

+96
-52
lines changed

3 files changed

+96
-52
lines changed

BrowserHistory/rock_paper_scissors.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Rock, Paper, Scissors Game (CLI Version)
3+
Author: Your Name
4+
"""
5+
6+
import random
7+
8+
9+
def get_user_choice():
10+
"""Prompt the user to enter their choice."""
11+
choice = input("Enter your choice (rock, paper, scissors): ").lower()
12+
if choice in ["rock", "paper", "scissors"]:
13+
return choice
14+
else:
15+
print("Invalid choice! Please enter rock, paper, or scissors.")
16+
return get_user_choice()
17+
18+
19+
def get_computer_choice():
20+
"""Randomly select computer's choice."""
21+
options = ["rock", "paper", "scissors"]
22+
return random.choice(options)
23+
24+
25+
def decide_winner(player, computer):
26+
"""Decide the winner based on the choices."""
27+
if player == computer:
28+
return "It's a draw!"
29+
elif (
30+
(player == "rock" and computer == "scissors")
31+
or (player == "paper" and computer == "rock")
32+
or (player == "scissors" and computer == "paper")
33+
):
34+
return "You win!"
35+
else:
36+
return "Computer wins!"
37+
38+
39+
def main():
40+
"""Main function to play the game."""
41+
user_choice = get_user_choice()
42+
computer_choice = get_computer_choice()
43+
print(f"Computer chose: {computer_choice}")
44+
print(decide_winner(user_choice, computer_choice))
45+
46+
47+
if __name__ == "__main__":
48+
main()

rock_paper_scissor_game.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

rock_paper_scissors.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Rock, Paper, Scissors Game
3+
Author: DEVANSH-GAJJAR
4+
"""
5+
6+
import random
7+
8+
9+
def get_user_choice():
10+
"""Prompt the user to enter their choice."""
11+
choice = input("Enter your choice (rock, paper, scissors): ").lower()
12+
if choice in ["rock", "paper", "scissors"]:
13+
return choice
14+
else:
15+
print("Invalid choice! Please enter rock, paper, or scissors.")
16+
return get_user_choice()
17+
18+
19+
def get_computer_choice():
20+
"""Randomly select computer's choice."""
21+
options = ["rock", "paper", "scissors"]
22+
return random.choice(options)
23+
24+
25+
def decide_winner(player, computer):
26+
"""Decide the winner based on the choices."""
27+
if player == computer:
28+
return "It's a draw!"
29+
elif (
30+
(player == "rock" and computer == "scissors")
31+
or (player == "paper" and computer == "rock")
32+
or (player == "scissors" and computer == "paper")
33+
):
34+
return "You win!"
35+
else:
36+
return "Computer wins!"
37+
38+
39+
def main():
40+
"""Main function to play the game."""
41+
user_choice = get_user_choice()
42+
computer_choice = get_computer_choice()
43+
print(f"Computer chose: {computer_choice}")
44+
print(decide_winner(user_choice, computer_choice))
45+
46+
47+
if __name__ == "__main__":
48+
main()

0 commit comments

Comments
 (0)