Answer to Question #186741 in Python for Vivek Reddy

Question #186741

Abhinav and Anjali are playing Rock-Paper-Scissors game. Rock-Paper-Scissors is a hand game usually played between two people, in which each player simultaneously forms one of three shapes with an outstretched hand. These shapes are "rock", "paper" and "scissors". Based on the shapes the player chooses the outcome of the game is determined. A rock beats scissors, scissors beat paper by cutting it, and paper beats rock by covering it. If the same shape is chosen by both of the players, then it is a tie. Write a program to decide the winner of each round of the game based on the shapes the players chose.

Given Inputs:

  1. Rock, Paper output is "Anjali wins"
  2. rock, scissors output is "Anjali wins"

code and explanation for this question


1
Expert's answer
2021-04-28T15:49:48-0400
abhinav = str(input("Abhinav's choice:"))
anjali = str(input("Anjali's choice:"))
if not ((anjali.lower() in ["rock", "paper", "scissors"]) and (abhinav.lower() in ["rock", "paper", "scissors"])):
    print("Invalid input")#Checking the correctness of the input
else:
    if abhinav.lower() == anjali.lower():#If both players made the same choice, then a draw
        print("Draw")
    elif abhinav.lower() == "rock":
        if anjali.lower() == "paper":
            print("Anjali wins")
        else:
            print("Abhinav wins")#If the first player chooses a rock, then he will lose to paper and win against the scissors
    elif abhinav.lower() == "paper":
        if anjali.lower() == "rock":
            print("Abhinav wins")
        else:
            print("Anjali wins")#If the first player chose paper, then he will lose with scissors and win against a rock
    elif abhinav.lower() == "scissors":
        if anjali.lower() == "rock":
            print("Anjali wins")
        else:
            print("Abhinav wins")#If the first player chooses scissors, then he will lose to the rock, he will win against the paper

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