-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrock_paper_scissor.py
More file actions
51 lines (38 loc) · 1.39 KB
/
rock_paper_scissor.py
File metadata and controls
51 lines (38 loc) · 1.39 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
48
49
50
51
from random import choice
import sys
class RPS:
def __init__(self) -> None:
print("Welcome to RPS 9000!")
self.moves: dict = {'rock': '🪨', 'paper': '📄', 'scissors': '✂️'}
self.valid_moves: list[str] = list(self.moves.keys())
def play_game(self):
user_move: str = input("Rock, paper, or scissors? >> ").lower()
if user_move == 'exit':
print('Thanks for playing!')
sys.exit()
if user_move not in self.valid_moves:
print('Invalid move ...')
self.play_game()
ai_move: str = choice(self.valid_moves)
self.display_moves(user_move, ai_move)
self.check_moves(user_move, ai_move)
def display_moves(self, user_move, ai_move):
print('----')
print(f'You: {self.moves[user_move]}')
print(f'AI: {self.moves[ai_move]}')
print('----')
def check_moves(self, user_move, ai_move):
if user_move == ai_move:
print('It\'s a tie!')
elif user_move == 'rock' and ai_move == 'scissors':
print('You win!')
elif user_move == 'paper' and ai_move == 'rock':
print('You win!')
elif user_move == 'scissors' and ai_move == 'paper':
print('You win!')
else:
print('AI win ...')
if __name__ == '__main__':
rps = RPS()
while True:
rps.play_game()