-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock paper scissors.py
32 lines (27 loc) · 1.08 KB
/
rock paper scissors.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
import random
def play_game():
choices = ['rock', 'paper', 'scissors']
computer_choice = random.choice(choices)
user_choice = input('Enter your choice (rock, paper, scissors): ')
while user_choice not in choices:
user_choice = input('Invalid choice. Enter again (rock, paper, scissors): ')
print(f'\nComputer chose: {computer_choice}')
print(f'You chose: {user_choice}\n')
if user_choice == computer_choice:
print(f'Both players selected {user_choice}. It\'s a draw !')
elif user_choice == 'rock':
if computer_choice == 'scissors':
print('Rock smashes scissors! You win!')
else:
print('Paper covers rock! You lose.')
elif user_choice == 'paper':
if computer_choice == 'rock':
print('Paper covers rock! You win!')
else:
print('Scissors cuts paper! You lose.')
elif user_choice == 'scissors':
if computer_choice == 'paper':
print('Scissors cuts paper! You win!')
else:
print('Rock smashes scissors! You lose.')
play_game()