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

1665 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Make a program that asks the user for a series of numbers until they either want to output the average or quit the program.


Write a function that takes an imput (call it usr_in), the user's age (usr_age) and the user's name (usr_nm) and outputs the following string: "Hi, My name is [usr_nm], I am [usr_age] years old, and my favorite number is [usr_in]"


Write a short program to print all the even numbers 1 to 100


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

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences