Create an rock, paper, scissors game. The user should input one option, and the computer should play randomly.

Possible solution: Firstly, two variable need to be created. The first variable is the one associated to the user's choice, while the second one is the one for the computer. The variable associated to the user, is created using the input statement, which will allow the user to write in the console. The variable associated to the computer is created by randint(0,3). This will create a random number between 0 and 2 (included). Now let's say 0 is paper, 1 is rock, and 2 is scissors. For each possible play of the computer there are 3 possible plays for the user. This is, if the computer hits a 0 (paper) there are three possibilities: the user can choose rock, paper or scissors. In this sense there are a total of 3^2=9 possibilities. Each possibility is taken into account as an if statement. A final variable with the answer is created before the ifs. This variable is started as empty. Then for each possible selection of the computer, the selection of the user is checked and the answer variable is changed accordingly to the rules. Let me show an example. if(computer==0): if(user=='paper'): answer='There is a tie' if(user='scissors'): answer='The user wins' if(user='rock'): answer='The computer wins'Now it's your turn to make the other 6 possibilities. Finally remember to print the answer statement in the console. Also you can modify the game to play rock, paper, scissors, lizard, Spock. Remember this solution is not unique, try to make your own!

AR
Answered by Alfredo R. Python tutor

1836 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Using the shared code editor, write a recursive function for calculating a factorial of an input parameter.


Implement a fibonacci function which calculates the nth number of the fibonacci sequence.


Create a python code to sum the number from 1 to 10.


Sort a given input of lowercase letters alphabetically


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

MyTutor is part of the IXL family of brands:

© 2026 by IXL Learning