Skip to content

Commit e567ef5

Browse files
authored
Create rock_paper_scissors.py
1 parent 0fed7b2 commit e567ef5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import random
2+
3+
def play_game():
4+
choices = ['rock', 'paper', 'scissors']
5+
6+
user_score = 0
7+
bot_score = 0
8+
9+
for _ in range(3):
10+
user_choice = input("Enter your choice (rock, paper, or scissors): ").lower()
11+
bot_choice = random.choice(choices)
12+
13+
if user_choice not in choices:
14+
print("Invalid choice. Please choose from rock, paper, or scissors.")
15+
continue
16+
17+
print(f"You chose {user_choice}. Bot chose {bot_choice}.")
18+
19+
if user_choice == bot_choice:
20+
print("It's a tie!")
21+
elif (user_choice == 'rock' and bot_choice == 'scissors') or (user_choice == 'paper' and bot_choice == 'rock') or (user_choice == 'scissors' and bot_choice == 'paper'):
22+
print("You win this round!")
23+
user_score += 1
24+
else:
25+
print("Bot wins this round!")
26+
bot_score += 1
27+
28+
if user_score > bot_score:
29+
print("You win the game!")
30+
elif user_score < bot_score:
31+
print("Bot wins the game!")
32+
else:
33+
print("It's a tie in the game!")
34+
35+
if __name__ == "__main__":
36+
play_game()

0 commit comments

Comments
 (0)