Machine Learning with Python Projects - Rock Paper Scissors

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0

Challenge: Machine Learning with Python Projects - Rock Paper Scissors

Link to the challenge:

I’d love to help you with this, but you need to explain your problem!

I have no Idea on how to get above the 60% on all 4 tests. Can you tell me how to do it?

My code:

def player(prev_play, opponent_history=[]):
  opponent_history.append(prev_play)
  choice = random.randint(1,100)
  #Slight Randomness Added to Vary results and confuse opponent algorithims
  if choice >=1 and choice <= 60:
    if prev_play == '':
          prev_play = "R"
    response = {'P': 'S', 'R': 'P', 'S': 'R'}
    #print(prev_play,response[prev_play])
    return response[prev_play]
  
  else:
    randguess = random.randint(1,3)
    if randguess == 1:
      guess = "R"
    elif randguess == 2:
      guess = "S"
    else:
      guess = "P"
    return guess

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.