Answer to Question #306734 in Python for Dhea M. Maddela

Question #306734

In the game Rock Paper Scissors, two players simultaneously choose one of the three options: rock, paper, scissors. If both player choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows:


• Rock beats scissors, because a rock can break a pair of scissors

• Scissors beats paper, because scissors can cut paper

• Paper beats rock, because a piece of paper can cover a rock


Create a Python script in which a computer randomly choose

rock, paper or scissors. Let the user enter a number 1, 2, or 3 each

representing one of the three choices. Then, determine the winner.


I need the code to have an output stated above.


1
Expert's answer
2022-03-06T04:49:49-0500
import random

print('1 Rock')
print('2 Paper')
print('3 Scissors')
print('  Your choise:')

computer = random.randint(1, 3)
player = int(input())

if player == computer:
  print('Draw')
elif player in [1, 2, 3]:
  if player == 1 && computer == 3 || player == 3 && computer == 2 || player == 2 && computer == 1:
    print('You won')
  else
    print('You lose')
else:
  print('Invalid choise')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS