forked from asweigart/the-big-book-of-small-python-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrockpaperscissorsalwayswin.py
60 lines (50 loc) · 1.6 KB
/
rockpaperscissorsalwayswin.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
52
53
54
55
56
57
58
59
60
"""Rock,Paper, Scissors (Always Win version)
By Al Sweigart [email protected]
The classic hand game of luck, except you always win.
This code is available at https://nostarch.com/big-book-small-python-programming
Tags: tiny, game, humor"""
import time, sys
print('''Rock, Paper, Scissors, by Al Sweigart [email protected]
- Rock beats scissors.
- Paper beats rocks.
- Scissors beats paper.
''')
# These variables keep track of the number of wins.
wins = 0
while True: # Main game loop.
while True: # Keep asking until player enters R, P, S, or Q.
print('{} Wins, 0 Losses, 0 Ties'.format(wins))
print('Enter your move: (R)ock (P)aper (S)cissors or (Q)uit')
playerMove = input('> ').upper()
if playerMove == 'Q':
print('Thanks for playing!')
sys.exit()
if playerMove == 'R' or playerMove == 'P' or playerMove == 'S':
break
else:
print('Type one of R, P, S, or Q.')
# Display what the player chose:
if playerMove == 'R':
print('ROCK versus...')
elif playerMove == 'P':
print('PAPER versus...')
elif playerMove == 'S':
print('SCISSORS versus...')
# Count to three with dramatic pauses:
time.sleep(0.5)
print('1...')
time.sleep(0.25)
print('2...')
time.sleep(0.25)
print('3...')
time.sleep(0.25)
# Display what the computer chose:
if playerMove == 'R':
print('SCISSORS')
elif playerMove == 'P':
print('ROCK')
elif playerMove == 'S':
print('PAPER')
time.sleep(0.5)
print('You win!')
wins = wins + 1