40.8k views
5 votes
Write a program that lets the user play the game Rock, Paper, Scissors against the computer. The program should:

1 Answer

3 votes

Answer:

import random

def simulateRound(choice, options):

compChoice = random.choice(options)

if choice == compChoice:

return ["Tie", compChoice]

elif choice == "rock" and compChoice == "paper":

return ["Loser", compChoice]

elif choice == "rock" and compChoice == "scissors":

return ["Winner", compChoice]

elif choice == "paper" and compChoice == "rock":

return ["Winner", compChoice]

elif choice == "paper" and compChoice == "scissors":

return ["Loser", compChoice]

elif choice == "scissors" and compChoice == "rock":

return ["Loser", compChoice]

elif choice == "scissors" and compChoice == "paper":

return ["Winner", compChoice]

else:

return ["ERROR", "ERROR"]

def main():

options = ["rock", "paper", "scissors"]

choice = input("Rock, Paper, or Scissors: ")

choice = choice.lower()

if choice not in options:

print("Invalid Option.")

exit(1)

result = simulateRound(choice, options)

print("AI Choice:", result[1])

print("Round Results:", result[0])

if __name__ == "__main__":

main()

Step-by-step explanation:

Program written in python.

Ask user to choose either rock, paper, or scissors.

Then user choice is simulated against computer choice.

Result is returned with computer choice.

Result is either "Winner", "Loser", or "Tie"

Cheers.

User Nstoitsev
by
6.0k points