Advertisement
asgfgh

Rock-Paper-Scissors

Jun 3rd, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. #Rock paper scissors game!
  2.  
  3. #ask for player names.
  4.  
  5. while True:
  6.   p1Name = input("What is Player One's name?\n")
  7.   p2Name = input("What is Player Two's name?\n")
  8.  
  9. #Get player answers, and make answers case sensitive.
  10.  
  11.   p1 = (input((p1Name + ': Rock, Paper, or Scissors?\n')))
  12.   p2 = (input((p2Name + ': Rock, Paper, or Scissors?\n')))
  13.  
  14.   p1 = p1.lower()
  15.   p2 = p2.lower()
  16.  
  17. #Invalid inputs
  18.  
  19.   if p1 != 'rock' and p1 != 'paper' and p1 != 'scissors':
  20.     print('Invalid input.')
  21.   elif p2 != 'rock' and p2 != 'paper' and p2 != 'scissors':
  22.     print('Invalid input.')
  23.    
  24. #Valid inputs
  25.  
  26.   elif p1 == 'rock' and p2 == 'scissors':
  27.     print(p1Name + ' has won!')
  28.   elif p1 == 'rock' and p2 == 'paper':
  29.     print(p2Name + ' has won!')
  30.   elif p1 == 'paper' and p2 == 'scissors':
  31.     print(p2Name + ' has won!')
  32.   elif p1 == 'paper' and p2 == 'rock':
  33.     print(p1Name + ' has won!')
  34.   elif p1 == 'scissors' and p2 == 'rock':
  35.     print(p2Name + ' has won!')
  36.   elif p1 == 'scissors' and p2 == 'paper':
  37.     print(p1Name + ' has won!')
  38.   elif p1 == p2:
  39.     print('It is a tie!')
  40.  
  41. #Play again?
  42.  
  43.   repeat = input('Do you want to play again?\n')
  44.   repeat = repeat.lower()
  45.   if repeat == 'yes' or 'y':
  46.     continue
  47.   else:
  48.     break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement