-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_06.py
31 lines (26 loc) · 1.15 KB
/
task_06.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
def rps_game_winner(*args):
#RPS
win_str = {
'RP': ['player2', 'P'],
'RS': ['player1', 'R'],
'RR': ['player1', 'R'],
'PS': ['player2', 'S'],
'PR': ['player1', 'P'],
'PP': ['player1', 'P'],
'SS': ['player1', 'S'],
'SP': ['player1', 'S'],
'SR': ['player2', 'R'],
}
class WrongNumberOfPlayersError(Exception):
def __init__(self, message):
super().__init__(message)
if len(args[0])!=2:
raise WrongNumberOfPlayersError("Wrong number of players")
if args[0][0][1].upper() not in 'RPS' or args[0][1][1].upper() not in 'RPS':
raise Exception("NoSuchStrategyError")
combination = str(args[0][0][1]) + str(args[0][1][1])
return f'{win_str[combination][0]} {win_str[combination][1]}'
print(rps_game_winner([['player1', 'P'], ['player2', 'S'], ['player3', 'S']])), # => WrongNumberOfPlayersError
print(rps_game_winner([['player1', 'P'], ['player2', 'A']])), #=> NoSuchStrategyError
print(rps_game_winner([['player1', 'P'], ['player2', 'S']])) #=> 'player2 S'
print(rps_game_winner([['player1', 'P'], ['player2', 'P']])) #=> 'player1 P')