-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrockpaperscissor.py
45 lines (41 loc) · 1.41 KB
/
rockpaperscissor.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
import random
#print the instructions
print("lets play a game of Rock paper scissor")
while True:
print("enter choice \n 1.>Rock \n 2.>Paper \n 3> Scissor")
#user input
choice = int(input("enter your guessed"))
#build a condition to loop is option is incorrect
if(choice > 1 or choice < 4):
#getting choice value
if choice == 1:
choice_name='Rock'
elif choice == 2:
choice_name='Paper'
else:
choice_name='Scissor'
#printing user choice
print("user choice is :" +choice_name)
print("computer turn")
#computer chooses randomly by ising randint method
comp_choice =random.randint(1,3)
# getting comp_choice choice value
if comp_choice == 1:
comp_choice_name = 'Rock'
elif comp_choice == 2:
comp_choice_name = 'Paper'
else:
comp_choice_name = 'Scissor'
print("computer name is :" +comp_choice_name)
#condition for game
if((choice==1 and comp_choice==2) or (choice==2 and comp_choice==1)):
result = "Paper"
elif((choice==2 and comp_choice==3) or (choice==3 and comp_choice==2)):
result ="Scissor"
else:
result = "Rock"
#print winner
if(result ==choice_name):
print("user is the winner")
else:
print("computer wins")