forked from mrizky-kur/Redux-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRPS.py
58 lines (54 loc) · 1.86 KB
/
RPS.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
import random
def game(player_name, ccount, pcount):
print("Pick a hand: (0: Rock, 1: Paper, 2: Scissors)")
player_hand = int(input("Please enter a number (0-2): "))
if validate(player_hand):
computer_hand = random.randint(0, 2)
if len(player_name) > 0:
print_hand(player_hand, player_name)
else:
player_name="Guest"
print_hand(player_hand, player_name)
print_hand(computer_hand, "Computer")
result = judge(player_hand, computer_hand)
if result=="Win":
pcount+=1
elif result=="Lose":
ccount+=1
print("Result: " + result)
resp(player_name, ccount, pcount)
else:
print("Please enter a valid number")
def resp(player_name, ccount, pcount):
response = input("Want to play again? (Y/N): ")
if response == "Y":
game(player_name, ccount, pcount)
elif response == "N":
if ccount > pcount:
print("Computer wins by " + str(ccount) + " - " + str(pcount))
elif pcount > ccount:
print(player_name + " wins by " + str(pcount) + " - " + str(ccount))
else:
print("Match draw by " + str(ccount) + " - " + str(pcount))
print("Thanks for playing")
else:
print("Please enter a valid response")
resp(player_name, ccount, pcount)
def validate(hand):
if hand<0 or hand>2:
return False
return True
def print_hand(hand, name):
hands=['Rock', 'Paper', 'Scissors']
print(name+' picked: '+hands[hand])
def judge(player, computer):
if player == computer:
return 'Draw'
elif player==0 and computer==1:
return 'Lose'
elif player==1 and computer==2:
return 'Lose'
elif player==2 and computer==0:
return 'Lose'
else:
return 'Win'