-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
35 lines (33 loc) · 1.3 KB
/
game.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
#importing random module for ability to randomize computer's choice
import random
winner = ""
#How a "random" choice is selected
randomChoice = random.randint(0,2)
#Assigning the numbers from the random choice into a string so it can be used for a comparison to the user's choice
if randomChoice == 0:
computerChoice = "Rock"
elif randomChoice == 1:
computerChoice = "Paper"
else:
computerChoice = "Scissors"
#Prompt to get the user's choice to eventually compare to the computer's choice
userChoice = ""
while (userChoice != "Rock" and
userChoice != "Paper" and
userChoice != "Scissors"):
userChoice = input("Rock, Paper or Scissors")
#Comparison and evalution of choices to determine whether the computer wins or the game ends in a tie
if computerChoice == userChoice:
winner="Tie"
elif computerChoice == "Paper" and userChoice == "Rock":
winner="Computer"
elif computerChoice == "Rock" and userChoice == "Scissors":
winner="Computer"
elif computerChoice == "Scissors" and userChoice == "Rock":
winner="Computer"
else:
winner="User"
if winner == "Tie":
print("We both chose", computerChoice + ", play again.")
else:
print(winner, "won. The computer chose", computerChoice + ".") #Closing satement declaring the winner (or tie) along with the computer's choice