Advertisement
phillipplasyt

Rock Paper Scissors

Sep 15th, 2019
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. import random
  2.  
  3. while True:
  4.     print('Make your choice:')
  5.     choice = str(input())
  6.     choice = choice.lower()
  7.  
  8.     print("My choice is", choice)
  9.  
  10.     choices = ['rock', 'paper', 'scissors']
  11.  
  12.     computer_choice = random.choice(choices)
  13.  
  14.     print("Computer choice is", computer_choice)
  15.     if choice in choices:
  16.         if choice == computer_choice:
  17.             print('it is a tie')
  18.         if choice == 'rock':
  19.             if computer_choice == 'paper':
  20.                 print('you lose, sorry :(')
  21.             elif computer_choice == 'scissors':
  22.                 print('You win!!!!! congrats :)')
  23.         if choice == 'paper':
  24.             if computer_choice == 'scissors':
  25.                 print('you lose, sorry :(')
  26.             elif computer_choice == 'rock':
  27.                 print('You win!!!!! congrats :)')
  28.         if choice == 'scissors':
  29.             if computer_choice == 'rock':
  30.                 print('you lose, sorry :(')
  31.             elif computer_choice == 'paper':
  32.                 print('You win!!!!! congrats :)')
  33.     else:
  34.         print('invalid choice, try again')
  35.  
  36.     print()
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. OR
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. import random
  58.  
  59. random.seed(42)
  60.  
  61. while True:
  62.     print("Make your guess:", end=" ")
  63.     guess = str(input())
  64.     guess = guess.lower()
  65.     print("you guessed", guess)
  66.     choices = ['rock', 'paper', 'scissors']
  67.     computer_guess = random.choice(choices)
  68.     print("computer guessed", computer_guess)
  69.     guess_dict = {'rock': 0, 'paper': 1, 'scissors': 2}
  70.     guess_idx = guess_dict.get(guess, 3)
  71.     computer_idx = guess_dict.get(computer_guess)
  72.     result_matrix = [[0,2,1],
  73.                      [1,0,2],
  74.                      [2,1,0],
  75.                      [3,3,3]]
  76.     result_idx = result_matrix[guess_idx][computer_idx]
  77.     result_messages = ["it is a tie", "You win!!! Congrats", 'the computer wins :(', 'invalid guess']
  78.     result = result_messages[result_idx]
  79.     print(result)
  80.     print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement