(Game: scissor, rock, paper) Write a program that plays the popular scissor-rockpaper game. (A scissor can cut a paper, a rock can knock a scissor, and a paper can wrap a rock.) The program randomly generates a number 0, 1, or 2 representing scissor, rock, and paper. The program prompts the user to enter a number 0, 1, or 2 and displays a message indicating whether the user or the computer wins, loses, or draws. Here are sample runs:
scissor (0), rock (1), paper (2): 1
The computer is scissor. You are rock. You won.
scissor (0), rock (1), paper (2): 2
The computer is paper. You are paper too. It is a draw.
#Import random module
import random
computer = random.randint(0,3)
#Prompt the user to enter a number 0, 1, or 2
print("scissor (0), rock (1), paper (2): ")
user = int(input())
print("The computer is ",end=" ")
switcher1={ 0: "scissor.",
1: "rock.",
2: "paper."
}
print(switcher1.get(computer),end="")
print(" You are ",end=" ")
switcher2={ 0:"scissor",
1: "rock",
2:"paper "
}
print(switcher2.get(user),end="")
#Display result
if (computer == user):
print(" too. It is a draw");
elif(user == 0 and computer == 2) or(user == 1 and computer == 0) or (user == 2 and computer == 1):
print(". You won.")
else:
print(". You lose.")
Output:
scissor (0), rock (1), paper (2):
2
The computer is rock. You are paper . You won.