Guest User

Untitled

a guest
Oct 15th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. import random
  2. import time
  3.  
  4. moves = ('rock', 'paper', 'scissors')
  5. winning_moves = {moves[0]: moves[1], moves[1]: moves[2], moves[2]: moves[0]}
  6.  
  7. def input_move():
  8.     while True:
  9.         move = input("Enter 1 for rock, 2 for paper, or 3 for scissors: ")
  10.         if move in list('123'):
  11.             return moves[int(move) - 1]
  12.         else:
  13.             print("Invalid input. Try again.")
  14.  
  15. victories = 0
  16. losses = 0
  17. ties = 0
  18. messages = "Rock... Paper... Scissors... Says... Shoot!".split()
  19. while True:
  20.     player_move = input_move()
  21.     print("\nYou played: {}\n".format(player_move))
  22.     for message in messages:
  23.         print(message)
  24.         time.sleep(.5)
  25.     computer_move = random.choice(moves)
  26.     print("\nComputer played: {}\n".format(computer_move))
  27.     if player_move == computer_move:
  28.         print("It's a tie!")
  29.         ties += 1
  30.     elif player_move == winning_moves[computer_move]:
  31.         print("You win!")
  32.         victories += 1
  33.     else:
  34.         print("You lose!")
  35.         losses += 1
  36.     print("Your record is: {} victories, {} losses, {} ties.\n"
  37.           "".format(victories, losses, ties))
Add Comment
Please, Sign In to add comment