-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock.py
51 lines (30 loc) · 1.35 KB
/
rock.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
# Set up. Import random function and establish winner variable
import random
winner = ''
# List of possible choices. Computer chooses
choices = ['rock','paper','scissors','lizard','spock']
computer_choice = random.choice(choices)
# Input user choice
user_choice = input('rock, paper, scissors, lizard or spock? ')
# Evaluate winner using game logic. If same, tie. Sets conditions of computer winning. No need to fully define user wins
if computer_choice == user_choice:
winner = 'Tie'
elif computer_choice == 'rock' and user_choice == 'scissor' or user_choice == 'lizard':
winner = 'Computer'
elif computer_choice == 'paper' and user_choice == 'rock' or user_choice == 'spock':
winner = 'Computer'
elif computer_choice == 'scissor' and user_choice == 'paper' or user_choice == 'lizard':
winner = 'Computer'
elif computer_choice == 'lizard' and user_choice == 'paper' or user_choice == 'spock':
winner = 'Computer'
elif computer_choice == 'spock' and user_choice == 'scissor' or user_choice == 'rock':
winner = 'Computer'
else:
winner = 'User'
# Gives results of tie or who won
if winner == 'Tie':
print('The computer chose', computer_choice,'and the user chose', user_choice)
print('It is a tie!')
else:
print('The computer chose', computer_choice,'and the user chose', user_choice)
print('The winner is', winner, '!')