DEV Community

Victory Ukachukwu
Victory Ukachukwu

Posted on

Easy Steps To Create Rock-Paper-Scissors Game with Python

import random

def the_game():
  player_choice = input("Enter a choice (rock, paper or scissors): ")
  options = ["rock", "paper", "scissors"]
  computer_choice = random.choice(options)
  response = {"player": player_choice, "computer": computer_choice}
  return response

def check_winner(player, computer):
  print(f"You chose {player}, computer chose {computer}")
  if player == computer:
    return "A tie!"
  elif player == "rock":
    if computer == "scissors":
      return "Rock smashes scissors! You win!"
    else:
      return "Paper covers rock. You lose."
  elif player == "paper":
    if computer == "paper":
      return "Paper covers rock. You win!"
    else:
      return "Scissors cuts paper. You lose."
  elif player == "scissors":
    if computer == "paper":
      return "Scissors cuts paper. You win!"
    else:
      return "Rock smashes scissors! You lose."

response = the_game()
score = check_winner(response["player"], response["computer"])
print(score)

Enter fullscreen mode Exit fullscreen mode

Top comments (0)