-
-
Notifications
You must be signed in to change notification settings - Fork 256
/
rock_paper_scissors.py
35 lines (27 loc) · 1.04 KB
/
rock_paper_scissors.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
"""
Implementation of rock, paper, scissors by Kylie Ying
YouTube Kylie Ying: https://www.youtube.com/ycubed
Twitch KylieYing: https://www.twitch.tv/kylieying
Twitter @kylieyying: https://twitter.com/kylieyying
Instagram @kylieyying: https://www.instagram.com/kylieyying/
Website: https://www.kylieying.com
Github: https://www.github.com/kying18
Programmer Beast Mode Spotify playlist: https://open.spotify.com/playlist/4Akns5EUb3gzmlXIdsJkPs?si=qGc4ubKRRYmPHAJAIrCxVQ
"""
import random
def play():
user = input("What's your choice? 'r' for rock, 'p' for paper, 's' for scissors\n")
computer = random.choice(['r', 'p', 's'])
if user == computer:
return 'It\'s a tie'
# r > s, s > p, p > r
if is_win(user, computer):
return 'You won!'
return 'You lost!'
def is_win(player, opponent):
# return true if player wins
# r > s, s > p, p > r
if (player == 'r' and opponent == 's') or (player == 's' and opponent == 'p') \
or (player == 'p' and opponent == 'r'):
return True
print(play())