Answer to Question #266032 in Python for prathyu

Question #266032
if input is rock, paper two player are plaing hand game how to write a program 
1
Expert's answer
2021-11-15T00:23:21-0500
import random


user_action = input("Enter your choice (rock, paper, scissors): ")
posb_actions = ["rock", "paper", "scissors"]
computer_action = random.choice(posb_actions)
print(f"\nYou chose {user_action}, computer chose {computer_action}.\n")


if user_action == computer_action:
    print(f"Both players selected {user_action}. It's a tie! No one will lose")
elif user_action == "rock":
    if computer_action == "scissors":
        print("Rock is harder than scissors! You won!")
    else:
        print("Paper easily covers rock! You lost.")
elif user_action == "paper":
    if computer_action == "rock":
        print("Paper covers rock! You win!")
    else:
        print("Scissors cuts paper! You lose.")
elif user_action == "scissors":
    if computer_action == "paper":
        print("Scissors cuts paper! You win!")
    else:
        print("Rock smashes scissors! You lose.")


#This code considered by expert Suhrob Umarov
        

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