-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path6_rock_paper_scissors.py
More file actions
57 lines (51 loc) · 2.3 KB
/
6_rock_paper_scissors.py
File metadata and controls
57 lines (51 loc) · 2.3 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import random, os, sys
computerscore = 0
userscore = 0
numgames = int(input("Welcome to rock, paper, scissors.\nHow many games would you like to play?\n"))
userinput = ""
computerchoice = ""
userwin = False
draw = False
choice = ""
clear = lambda: os.system("cls")
for x in range(0, numgames):
generatednum = random.randint(1,3)
if generatednum == 1:
computerchoice = "rock"
elif generatednum == 2:
computerchoice = "paper"
elif generatednum == 3:
computerchoice = "scissors"
userinput = input("Select rock, paper, or scissors\n")
if userinput == "rock" and computerchoice == "scissors":
print("You selected",userinput,"and the computer selected",computerchoice,"You won this round!")
userscore += 1
elif userinput == "rock" and computerchoice == "paper":
print("You selected",userinput,"and the computer selected",computerchoice,"You lost this round!")
computerscore += 1
if userinput == "paper" and computerchoice == "rock":
print("You selected",userinput,"and the computer selected",computerchoice,"You won this round!")
userscore += 1
elif userinput == "paper" and computerchoice == "scissors":
print("You selected",userinput,"and the computer selected",computerchoice,". You lost this round!")
computerscore += 1
if userinput == "scissors" and computerchoice == "paper":
print("You selected",userinput,"and the computer selected",computerchoice,"You won this round!")
userscore += 1
elif userinput == "scissors" and computerchoice == "rock":
print("You selected",userinput,"and the computer selected",computerchoice,"You lost this round!")
computerscore += 1
if userscore > computerscore:
userwin = True
elif userscore == computerscore:
draw = True
if userwin == True:
print("Congratulations, you won!\nYour score:",userscore,"\nComputer's score:",computerscore)
elif draw == True:
print("You drew!\nYour score:",userscore,"\nComputer's score:",computerscore)
elif userwin == False:
print("I'm sorry, but you lost.\nYour score:",userscore,"\nComputer's score:",computerscore)
choice = str(input("Would you like to play again? y/n\n"))
if choice == "y":
clear()
os.system("rockpaperscissors.py")