Skip to content

Commit 9e464f6

Browse files
committed
Added Rock Paper Scissors script
1 parent 7eb6321 commit 9e464f6

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<div align="center">
2+
3+
# Rock, Paper, Scissors Game
4+
5+
</div>
6+
7+
### Description:
8+
This Python script allows the user to play the classic Rock, Paper, Scissors game against the computer.
9+
10+
### How to Use:
11+
1. Run the script in a Python environment.
12+
2. Enter your choice (rock, paper, or scissors) when prompted.
13+
3. The script will randomly generate the computer's choice and determine the winner based on the rules of the game.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import random
2+
3+
4+
def play_game(user_choice):
5+
options = ["rock", "paper", "scissors"]
6+
computer_choice = random.choice(options)
7+
print(f"Computer chooses: {computer_choice}")
8+
if user_choice == computer_choice:
9+
return "It's a tie!"
10+
elif (user_choice == "rock" and computer_choice == "scissors") or \
11+
(user_choice == "paper" and computer_choice == "rock") or \
12+
(user_choice == "scissors" and computer_choice == "paper"):
13+
return "You win!"
14+
else:
15+
return "Computer wins!"
16+
17+
18+
def main():
19+
user_choice = input("Enter your choice (rock/paper/scissors): ").lower()
20+
if user_choice not in ["rock", "paper", "scissors"]:
21+
print("Invalid choice!")
22+
else:
23+
print(play_game(user_choice))
24+
25+
26+
if __name__ == "__main__":
27+
main()

0 commit comments

Comments
 (0)