Rock Paper Scissors (Always Win Version)
This variant of Rock Paper Scissors is identical to Project 59, “Rock Paper Scissors,” except the player will always win. The code selecting the computer’s move is set so that it always chooses the losing move. You can offer this game to your friends, who may be excited when they win … at first. See how long it takes before they catch on to the fact that the game is rigged in their favor.
rock_paper_scissors_always-win_version.py
1"""Rock,Paper, Scissors (Always Win version)
2By Al Sweigart al@inventwithpython.com
3The classic hand game of luck, except you always win.
4This code is available at https://nostarch.com/big-book-small-python-programming
5Tags: tiny, game, humor"""
6
7import time, sys
8
9print('''Rock, Paper, Scissors, by Al Sweigart al@inventwithpython.com
10- Rock beats scissors.
11- Paper beats rocks.
12- Scissors beats paper.
13''')
14
15# These variables keep track of the number of wins.
16wins = 0
17
18while True: # Main game loop.
19 while True: # Keep asking until player enters R, P, S, or Q.
20 print('{} Wins, 0 Losses, 0 Ties'.format(wins))
21 print('Enter your move: (R)ock (P)aper (S)cissors or (Q)uit')
22 playerMove = input('> ').upper()
23 if playerMove == 'Q':
24 print('Thanks for playing!')
25 sys.exit()
26
27 if playerMove == 'R' or playerMove == 'P' or playerMove == 'S':
28 break
29 else:
30 print('Type one of R, P, S, or Q.')
31
32 # Display what the player chose:
33 if playerMove == 'R':
34 print('ROCK versus...')
35 elif playerMove == 'P':
36 print('PAPER versus...')
37 elif playerMove == 'S':
38 print('SCISSORS versus...')
39
40 # Count to three with dramatic pauses:
41 time.sleep(0.5)
42 print('1...')
43 time.sleep(0.25)
44 print('2...')
45 time.sleep(0.25)
46 print('3...')
47 time.sleep(0.25)
48
49 # Display what the computer chose:
50 if playerMove == 'R':
51 print('SCISSORS')
52 elif playerMove == 'P':
53 print('ROCK')
54 elif playerMove == 'S':
55 print('PAPER')
56
57 time.sleep(0.5)
58
59 print('You win!')
60 wins = wins + 1