forked from mosh-hamedani/python-projects-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrock_paper_scissor.py
More file actions
47 lines (36 loc) · 1.17 KB
/
rock_paper_scissor.py
File metadata and controls
47 lines (36 loc) · 1.17 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
import random
ROCK = 'r'
SCISSORS = 's'
PAPER = 'p'
emojis = { ROCK: '🪨', SCISSORS: '✂️', PAPER: '📃' }
choices = tuple(emojis.keys())
def get_user_choice():
while True:
user_choice = input('Rock, paper, or scissors? (r/p/s): ').lower()
if user_choice in choices:
return user_choice
else:
print('Invalid choice!')
def display_choices(user_choice, computer_choice):
print(f'You chose {emojis[user_choice]}')
print(f'Computer chose {emojis[computer_choice]}')
def determine_winner(user_choice, computer_choice):
if user_choice == computer_choice:
print('Tie!')
elif (
(user_choice == ROCK and computer_choice == SCISSORS) or
(user_choice == SCISSORS and computer_choice == PAPER) or
(user_choice == PAPER and computer_choice == ROCK)):
print('You win')
else:
print('You lose')
def play_game():
while True:
user_choice = get_user_choice()
computer_choice = random.choice(choices)
display_choices(user_choice, computer_choice)
determine_winner(user_choice, computer_choice)
should_continue = input('Continue? (y/n): ').lower()
if should_continue == 'n':
break
play_game()