paper scissors rock python game

Solution 1:

Make sure your indentation is correct.

import random
options = ['rock','paper','scissors']

def game(rounds):
  roundNum = 1
  playerScore = 0
  computerScore = 0

  while roundNum <= rounds:
      print('Round Number '+ str(roundNum))
      Player = input('Please choose rock, paper or scissors')
      computer =  options[random.randint(0,2)]
      print(computer)

Solution 2:

The issue is with the indentation of while loop.

As function game and while are at same level any object declared inside the game function will be out of scope/unreachable for while loop.

A simple tab will resolve the issue in this case as follow :

import random
options = ['rock','paper','scissors']

def game(rounds):
    roundNum = 1
    playerScore = 0
    computerScore = 0

    while roundNum <= rounds:
      print('Round Number '+ str(roundNum))
      Player = input('Please choose rock, paper or scissors')
      computer =  options[random.randint(0,2)]
      print(computer)