forked from mayankchaudhary26/HacktoberFest-Practice-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrock_paper_scissors.py
More file actions
42 lines (32 loc) Β· 1.4 KB
/
rock_paper_scissors.py
File metadata and controls
42 lines (32 loc) Β· 1.4 KB
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
# Importing the necessary modules
import random
#Declaring a pre-defined set of outcomes
outputs = ['rock','paper','scissor']
# Initialising scores of computer and user
user = 0
computer = 0
name = input("Enter your name: ")
n = int(input("Enter the number of rounds: "))
# Playing for n rounds
for i in range(1,n+1):
temp1 = input("Enter rock, paper or scissor: ")
# Generating a choice for the computer using random library
temp2 = random.choice(outputs)
# If user choice and computer's choice is same, it's a tie
if (temp1==temp2):
print("Round "+str(i)+" is tied")
# If user beats computer, increment user's score by 1
elif ((temp1=='rock')and(temp2=='scissor'))or((temp1=='paper') and (temp2=='rock')) or ((temp1=='scissor')and(temp2=='paper')):
user +=1
print("Round "+str(i)+" is won by user")
# If computer beats user, increment computer's score by 1
elif ((temp2=='rock')and(temp1=='scissor'))or((temp2=='paper') and (temp1=='rock')) or ((temp2=='scissor')and(temp1=='paper')):
computer += 1
print("Round "+str(i)+" is won by computer")
# Display the results
if user>computer:
print("\n #### After "+str(n)+" rounds of play, "+name+" wins! #### \n")
elif computer>user:
print("\n #### After "+str(n)+" rounds of play, Computer wins! #### \n")
else:
print("\n #### After "+str(n)+" rounds of play, It's a tie! #### \n")