User Input

Learn to get the user’s input in the console.

What have we got?

We have set up taking the number of rounds from the user and the game’s introduction. 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

In this task, we must request user input to select one of the three options.

What’s next?

We now need to create a function that takes the user’s choice as input. We can follow these steps to complete this task:

  • Ask the user for their choice and store it in a variable.
  • Return the variable.

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 1400+ tech skills courses.