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 (8)

Collapse
 
shurwood_840b883d3a1ae4a2 profile image
Shawn

I have noticed that in the picture I sent of my replit code that after my "Return "It's a tie!" statement, that the rest of that code is darker then what is above my return statement. Could this be what is hindering my code from working properly?

Collapse
 
shurwood_840b883d3a1ae4a2 profile image
Shawn

Today, I've tried to tweak the code on my own and learned that I can't replace my second if statement with an "and" or "or" statement. Replit will find it as an error.

Collapse
 
shurwood_840b883d3a1ae4a2 profile image
Shawn

I am still working on figuring out why my code is not working but I've recently learned that integer values or int can help the computer store information that it translates into string values, or str.

Thread Thread
 
shurwood_840b883d3a1ae4a2 profile image
Shawn

Still working on my rock-paper-scissors game, but I've learned how to add and subtract numbers in Python using str and int values.

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.