TheRodMeister
10/18/2018 - 9:20 PM

Rock Paper Scisors

comparing values based on differences in rock paper scissors


#Note: this was worked out on paper before hand
#associate numbers with game input
gameDict = {
   'R':1,
   'P':2,
   'S':3
}
#turns counter
turns = 0

while True:
   #ask input
   playerOneInput = input('Player 1, choose R, P, S: ')
   playerTwoInput = input('player 2, choose R, P, S: ')

   #retrieve game dict values
   dictVal1 = gameDict[playerOneInput]
   dictVal2 = gameDict[playerTwoInput]

   #we use a difference among dict values to compare winner
   difference = dictVal1 - dictVal2

   #player one wins when diff are [-2,1,1]
   #player two wins when diff are [2,-1,-1]
   #based on the differences of dict values, either player 1 or player 2 wins
   #change or to in
   if difference in [-2,1]
      print('player One wins')
   elif difference == 0: #draw if difference is 0, S & S, 3 - 3
      print('draw')
   else:
      print('player Two wins')

   #break out of loop after 7 turns
   turns +=1

   if turns == 7:
      break






"C:\Python Practice Exercises 2.0\venv\Scripts\python.exe" C:/Users/rnata/.PyCharmCE2018.2/config/scratches/scratch_3.py
Player 1, choose R, P, S: R
player 2, choose R, P, S: R
Draw
Player 1, choose R, P, S: R
player 2, choose R, P, S: S
player One wins
Player 1, choose R, P, S: P
player 2, choose R, P, S: R
player One wins
Player 1, choose R, P, S: S
player 2, choose R, P, S: P
player One wins
Player 1, choose R, P, S: S
player 2, choose R, P, S: R
player Two wins
Player 1, choose R, P, S: R
player 2, choose R, P, S: P
player Two wins
Player 1, choose R, P, S: P
player 2, choose R, P, S: S
player Two wins

Process finished with exit code 0