Computer’s Move

Learn to generate the computer's move.

What have we got?

We have set up the user’s input. This is our inventory of already created functions:

# Function to display game instructions
def display_instructions():
    print('Welcome to Rock Paper Scissors.\n')
    print('The rules are simple:')
    print('1. Rock beats scissors')
    print('2. Scissors beat paper')
    print('3. Paper beats rock')

# Function to ask for the number of rounds
def get_rounds():
    rounds = input('\nHow many rounds would you like to play? \nRounds: ')
    rounds = int(rounds)
    return rounds

# Function to get the player’s choice
def get_player_choice():
    player_choice = input('\nPlease enter rock, paper, or scissors. \nChoice: ')
    return player_choice

In this task, we will create a function to get a move from the computer.

What’s next?

We’ll use the choice function in Python’s random library to choose one of the three options and return that option as the computer’s choice.

Try it yourself

Write your code in the code widget below and click the “Run” button to execute your code.

If you’re unsure how to do this, click the “Show Hint” button.

Get hands-on with 1200+ tech skills courses.