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 (9)
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?
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.
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.
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.
Still working on my rock-paper-scissors game. However, I've recently found a tutorial video that will teach me about if, else and elif statements even more. The mystery to this game will soon be solved!
(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.