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!
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (4)
(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?
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?
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.
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.