-
Notifications
You must be signed in to change notification settings - Fork 0
/
sps .py
34 lines (28 loc) · 1.12 KB
/
sps .py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import random
def get_user_choice():
while True:
user_choice = input("Choose rock, paper, or scissors: ").lower()
if user_choice in ['rock', 'paper', 'scissors']:
return user_choice
else:
print("Invalid choice! Please choose rock, paper, or scissors.")
def get_computer_choice():
choices = ['rock', 'paper', 'scissors']
return random.choice(choices)
def determine_winner(user_choice, computer_choice):
if user_choice == computer_choice:
return "It's a tie!"
elif (user_choice == 'rock' and computer_choice == 'scissors') or \
(user_choice == 'paper' and computer_choice == 'rock') or \
(user_choice == 'scissors' and computer_choice == 'paper'):
return "You win!"
else:
return "Computer wins!"
def play_game():
print("Let's play Rock, Paper, Scissors!")
user_choice = get_user_choice()
computer_choice = get_computer_choice()
print(f"You chose: {user_choice}")
print(f"Computer chose: {computer_choice}")
print(determine_winner(user_choice, computer_choice))
play_game()