-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject1.py
80 lines (56 loc) · 2.13 KB
/
Project1.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
# Program to build rock, paper, scissor game using python:
import random # importing random module for computer's choice
######################################
# defining function and checking for all possibilities
def result(comp, user):
if comp == user: # if both selected same object
return None
elif comp == 'rock': # if computer selected rock then check for all possibilities
if user == 's':
return False
elif user == 'p':
return True
elif comp == 'paper': # if comp selected paper then checking all possibilities
if user == 'r':
return False
elif user == 's':
return True
elif comp == 'scissor': # if comp selected scissor selected then checkin for all possibilities
if user == 'p':
return False
elif user == 'r':
return True
##############################################
print("Computer's turn : Selecting........Done!!")
# random module operation for comp selection choice
num = random.randint(1, 3)
if num == 1:
computer = 'rock'
elif num == 2:
computer = 'scissor'
elif num == 3:
computer = 'paper'
###############################################
# taking user input choice
player = input("Player's turn : Please select your choice from Rock(r), Paper(p),Scissor(s) : \n")
if player == 'r': # printing choices as a word for user ---> eg. r = rock
u = 'rock'
elif player == 's':
u = 'scissor'
elif player == 'p':
u = 'paper'
##############################################
print('########_____The Game___#########')
# printing the choices for both
print('computer selected :', computer)
print('user selected :', u)
############################################
# using above function to declare result of input of both players
winner = result(computer, player)
if winner == None:
# printing the result of the game by passing booleans from the function
print('The game is a tie. Play again....')
elif winner == True:
print('You win.')
else:
print('You lost.')