Advertisement
asweigart

rpsgame.py

May 31st, 2019
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. import random, time
  2.  
  3. while True: # Keep asking until the player enters a valid move:
  4.     print('Enter your move: (r)ock (p)aper (s)cissors or (q)uit')
  5.     player = input()
  6.     if player == 'r' or player == 'p' or player == 's':
  7.         break # Break out of the player input loop.
  8.     print('Type one of r, p, or s.')
  9.  
  10. # Display what the player chose:
  11. if player == 'r':
  12.     print('ROCK versus...')
  13. elif player == 'p':
  14.     print('PAPER versus...')
  15. elif player == 's':
  16.     print('SCISSORS versus...')
  17.  
  18. # Add dramatic pause:
  19. print('3')
  20. time.sleep(1)
  21. print('2')
  22. time.sleep(1)
  23. print('1')
  24.  
  25. # Display what the computer chose:
  26. computer = random.choice(['r', 'p', 's'])
  27. if computer == 'r':
  28.     print('ROCK')
  29. elif computer == 'p':
  30.     print('PAPER')
  31. elif computer == 's':
  32.     print('SCISSORS')
  33.  
  34. # Display the result:
  35. if player == computer:
  36.     print('It is a tie!')
  37. elif (player == 'r' and computer == 's') or (player == 'p' and computer == 'r') or (player == 's' and computer == 'p'):
  38.     print('You win!')
  39. elif (player == 'r' and computer == 'p') or (player == 'p' and computer == 's') or (player == 's' and computer == 'r'):
  40.     print('You lose!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement