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:
code and explanation for this question
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
Comments
Leave a comment