HW 2 (Game: scissor, rock, paper) Write a program that plays the popular scissor
ID: 3746350 • Letter: H
Question
HW 2 (Game: scissor, rock, paper) Write a program that plays the popular scissor-rock- pager 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): 1t The computer is scissor. You are rock. You won. scissor (0), rock (1), paper (2): 2nter The computer is paper. You are paper too. It is a draw.Explanation / Answer
from random import randint def choice_string(choice): if choice == 0: return 'scissor' elif choice == 1: return 'rock' else: return 'paper' def main(): computer_choice = randint(0, 2) player_choice = int(input('scissor (0), rock (1), paper (2): ')) if computer_choice == player_choice: print('The computer choice is %s. You are %s. It is a draw.' % (choice_string(computer_choice), choice_string(player_choice))) elif (computer_choice == 0 and player_choice == 1) or (computer_choice == 1 and player_choice == 2) or (computer_choice == 2 and player_choice == 0): print('The computer choice is %s. You are %s. You won.' % (choice_string(computer_choice), choice_string(player_choice))) else: print('The computer choice is %s. You are %s. Computer won.' % (choice_string(computer_choice), choice_string(player_choice))) main()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.