DEV Community

Cover image for Rock Doesn't Beat Scissors? Replit sees it as a tie? Help!
Shawn
Shawn

Posted on

Rock Doesn't Beat Scissors? Replit sees it as a tie? Help!

Hello! I was trying to follow a video and create the above replit, however, whenever I click "Run", no matter what option I pick: rock, paper, or scissors, the computer will choose a random input, but I have it set up in the code to where, if I chose rock and the computer chose scissors, it should say "You Won!", not "It's a tie!" I'm just starting out with Python, but would love to know where I've gone wrong with the code to fix it. For reference, the video I am using is: "https://www.youtube.com/watch?v=eWRfhZUzrAc". Thank you!

Top comments (4)

Collapse
 
shurwood_840b883d3a1ae4a2 profile image
Shawn

(rock, paper, scissors: ")
options = ["rock", "paper", "scissors"]
computer_choice = random.choice(options)
choices = {"player": player_choice, "computer_choice": computer_choice}
return choices

def check_win(player, computer):
print(f"You chose { player}, computer chose { computer}")
return "It's a tie!"
if player == "rock":
if computer == "scissors":
return "Rock smashes scissors! You win!"

choices = get_choices()
result = check_win(choices["player"], choices["computer_choice"])
print(result).
This is the code that I used in Replit. Should it contain a different element or something else that makes it actually work?

Collapse
 
shurwood_840b883d3a1ae4a2 profile image
Shawn

Should I continue adding definitions so that Replit understands that each response should be different? If I do, should I use 1 elif statement for every 2 additional if statement, or vice versa?

Collapse
 
muhammadubarry profile image
Muhammadu Barry

You have to show your code for us to review, just because you linked the video doesn't mean we will understand what's going on; be specific and share your code for people to look at it and help you out.

Collapse
 
shurwood_840b883d3a1ae4a2 profile image
Shawn

Oh! Does the picture not show up? I had to refresh my page in order to see it again. Here is the code that I used:import random
def get_choices():
player_choice = input("Enter a choice (rock, paper, scissors: ")
options = ["rock", "paper", "scissors"]
computer_choice = random.choice(options)
choices = {"player": player_choice, "computer_choice": computer_choice}
return choices

def check_win(player, computer):
print(f"You chose { player}, computer chose { computer}")
return "It's a tie!"
if player == "rock":
if computer == "scissors":
return "Rock smashes scissors! You win!"

choices = get_choices()
result = check_win(choices["player"], choices["computer_choice"])
print(result).
When I click run, it will play the game for a second, but after I choose, it will always say that it is a tie.