Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random, time
- while True: # Keep asking until the player enters a valid move:
- print('Enter your move: (r)ock (p)aper (s)cissors or (q)uit')
- player = input()
- if player == 'r' or player == 'p' or player == 's':
- break # Break out of the player input loop.
- print('Type one of r, p, or s.')
- # Display what the player chose:
- if player == 'r':
- print('ROCK versus...')
- elif player == 'p':
- print('PAPER versus...')
- elif player == 's':
- print('SCISSORS versus...')
- # Add dramatic pause:
- print('3')
- time.sleep(1)
- print('2')
- time.sleep(1)
- print('1')
- # Display what the computer chose:
- computer = random.choice(['r', 'p', 's'])
- if computer == 'r':
- print('ROCK')
- elif computer == 'p':
- print('PAPER')
- elif computer == 's':
- print('SCISSORS')
- # Display the result:
- if player == computer:
- print('It is a tie!')
- elif (player == 'r' and computer == 's') or (player == 'p' and computer == 'r') or (player == 's' and computer == 'p'):
- print('You win!')
- elif (player == 'r' and computer == 'p') or (player == 'p' and computer == 's') or (player == 's' and computer == 'r'):
- print('You lose!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement