**Tell us what’s happening:**

Describe your issue in detail here.

My code runs fine in Pycharm but when I switch to Replit I get this error:

Traceback (most recent call last):

File “/home/runner/boilerplate-rock-paper-scissors/main.py”, line 6, in

play(player, quincy, 1000)

File “/home/runner/boilerplate-rock-paper-scissors/RPS_game.py”, line 12, in play

p1_play = player1(p2_prev_play)

File “/home/runner/boilerplate-rock-paper-scissors/RPS.py”, line 180, in player

update_matrix(pair_diff2[-1])

File “/home/runner/boilerplate-rock-paper-scissors/RPS.py”, line 152, in update_matrix

matrix[pair][prev_play][‘n_obs’] = matrix[pair][prev_play][‘n_obs’] + 1

KeyError: ‘’

exit status 1

**Your code so far**

import random

def player(

prev_play,

opponent_history=,

my_history=[‘S’],

matrix={

‘PP’: {

‘R’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘P’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘S’: {

‘prob’: 0.33333,

‘n_obs’: 0

}

},

‘PR’: {

‘R’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘P’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘S’: {

‘prob’: 0.333333,

‘n_obs’: 0

}

},

‘PS’: {

‘R’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘P’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘S’: {

‘prob’: 0.333333,

‘n_obs’: 0

}

},

‘RP’: {

‘R’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘P’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘S’: {

‘prob’: 0.33333,

‘n_obs’: 0

}

},

‘RR’: {

‘R’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘P’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘S’: {

‘prob’: 0.333333,

‘n_obs’: 0

}

},

‘RS’: {

‘R’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘P’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘S’: {

‘prob’: 0.333333,

‘n_obs’: 0

}

},

‘SP’: {

‘R’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘P’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘S’: {

‘prob’: 0.33333,

‘n_obs’: 0

}

},

‘SR’: {

‘R’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘P’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘S’: {

‘prob’: 0.333333,

‘n_obs’: 0

}

},

‘SS’: {

‘R’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘P’: {

‘prob’: 0.333333,

‘n_obs’: 0

},

‘S’: {

‘prob’: 0.333333,

‘n_obs’: 0

}

}

},

pair_diff2=,

pair_diff1=[‘SS’]

):

decay = 0.7

keys = [‘R’, ‘P’, ‘S’]

beat = {‘R’: ‘P’, ‘P’: ‘S’, ‘S’: ‘R’}

```
def rand_predict():
return random.choice(['R', 'P', 'S'])
def update_matrix(pair):
for i in keys:
matrix[pair][i]['n_obs'] = decay * matrix[pair][i]['n_obs']
matrix[pair][prev_play]['n_obs'] = matrix[pair][prev_play]['n_obs'] + 1
n_total = 0
for i in keys:
n_total += matrix[pair][i]['n_obs']
for i in keys:
matrix[pair][i]['prob'] = matrix[pair][i]['n_obs'] / n_total
def predict(pair):
comp = []
for i in keys:
comp.append(matrix[pair][i]['prob'])
if max(comp) == min(comp):
return rand_predict()
else:
for i in keys:
if matrix[pair][i]['prob'] == max(comp):
return i
pair_diff2.append(pair_diff1[-1])
pair_diff1.append(my_history[-1] + prev_play)
opponent_history.append(prev_play)
if len(pair_diff2) != 0:
update_matrix(pair_diff2[-1])
output = beat[predict(pair_diff1[-1])]
else:
output = rand_predict()
my_history.append(output)
return output
```

**Your browser information:**

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 OPR/95.0.0.0`

**Challenge:** Machine Learning with Python Projects - Rock Paper Scissors