-
Notifications
You must be signed in to change notification settings - Fork 1
/
rock_paper_scissors.py
85 lines (67 loc) · 2.04 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def input_moves(player:int):
player_move = input(f"Player {player}, what's your first move? ").lower()
return player_move
def input_validator(word):
accepted_inputs = {
"rock": True,
"paper": True,
"scissors": True,
"yes": True,
}
if word in accepted_inputs:
return accepted_inputs.get(word)
else:
return False
def comparator(player_one, player_two):
if player_one == player_two:
return 0
else:
pass
if player_one == "rock":
if player_two == "scissors":
return 1
elif player_two == "paper":
return 2
else:
pass
if player_one == "scissors":
if player_two == "paper":
return 1
elif player_two == "rock":
return 2
else:
pass
if player_one == "paper":
if player_two == "rock":
return 1
elif player_two == "scissors":
return 2
else:
pass
def player_input(player_no):
player_input = input_moves(player_no)
while not input_validator(player_input):
print("Try again!")
player_input = input_moves(player_no)
return player_input
def play_again():
player_wanna_play = input("Do you want to play again?").lower()
return input_validator(player_wanna_play)
def main():
# Run input_moves to get player 1 move, if wrong ask to input again till input is rock, paper or scissors. Repeat for player 2.
player_wanna_play = True
while player_wanna_play:
player_one = player_input(1)
player_two = player_input(2)
comparator(player_one, player_two)
if comparator(player_one, player_two) == 1:
print("Player 1 wins!")
elif comparator(player_one, player_two) == 2:
print("Player 2 wins!")
elif comparator(player_one, player_two) == 0:
print("It's a draw!")
else:
print("error")
player_wanna_play = play_again()
if __name__ == '__main__':
main()