forked from Aman22sharma/Hacktoberfest2021_beginner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rock_paper_scissor_mayankgoyal.py
43 lines (37 loc) · 1.23 KB
/
Rock_paper_scissor_mayankgoyal.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
"""
Name : Rock Paper Scissor Game
Author : [Mayank Goyal) [https://github.com/mayankgoyal-13]
"""
import random
def validate(hand):
if hand < 0 or hand > 2:
return False
return True
def print_hand(hand, name='Guest'):
hands = ['Rock', 'Paper', 'Scissors']
print(name + ' picked: ' + hands[hand])
def judge(player, computer):
# comparison of player and 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'
print('Starting the Rock Paper Scissors game!')
player_name = input('Please enter your name: ')
print('Pick a hand: (0: Rock, 1: Paper, 2: Scissors)')
player_hand = int(input('Please enter a number (0-2): '))
if validate(player_hand):
# the computer chooses a random value and each value is assigned to a hand
computer_hand = random.randint(0, 2)
print_hand(player_hand, player_name)
print_hand(computer_hand, 'Computer')
result = judge(player_hand, computer_hand) # judge function is called
print('Result: ' + result)
else:
print('You entered an invalid option')