Python Forum

Full Version: Rock, Paper, Scissors Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to code a rock, paper, scissors game but am struggling with the final step. When I run the module, it does everything up to showing what the computer chose. However, it does not finish the code and display the result of the game. I am very new to python so any help is appreciated. Here is the code:
from random import randint

print ("Welcome to Rock, Paper, Scissors")
print ("Try to beat this program in a simple game of Rock, Paper, Scissors.")
player = input('Rock, paper, or scissors ')
if player == 'rock':
  player == 'r'
  
elif player == 'paper':
  player == 'p'
  
elif player == 'scissors':
  player == 's'
  
chosen = randint(1,3)

if chosen == 1 :
  computer = "rock"
  print ("computer chose rock")
elif chosen == 2 :
  computer = "paper"
  print ("computer chose paper")
else:
  computer = "scissors"
  print ("computer chose scissors")
  
def func(player, computer):
  if player == 's' and computer == "rock":
    return ("You lost!")
  elif player == 's' and computer == "paper":
    return "You win!"
  elif player == 's' and computer == "scissors":
    return "You tied!"
  elif player == 'r' and computer == "rock":
    return "You tied!"
  elif player == 'r' and computer == "paper":
    return "You lost!"
  elif player == 'r' and computer == "scissors":
    return "You win!"
  elif player == 'p' and computer == "rock":
    return "You win!"
  elif player == 'p' and computer == "paper":
    return "You tied!"
  elif player == 'p' and computer == "scissors":
    return "You lost!"
You define a function, func, which contains the logic for determining who won, but you never call that function. At the bottom of your code, if you add the line print(func(player, computer)), it should do as you expect.

Also, I don't think this is doing what you think it does. Take a look at it, and see if you can figure out why:
if player == 'rock':
  player == 'r'