#๐Ÿ”’ Rock Paper Scissor code review

13 messages ยท Page 1 of 1 (latest)

south sundialBOT
#

@left vapor

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

junior kernel
#

@left vapor You define running on line 4, but you reference to it on line 14, 20, 26, 55, and 59 as Running and only on line 51 do you reference it as running.

pure plank
#

Did you test that it works?

#

Well, apparently you didn't test that the exiting via running works

#

But my review would be: There's tons of unneeded redundancy in there. I would propose making a function that takes two choices as arguments and determines who wins, and then just call that on the two inputs, rather than handling every possible case by hand.

#

The "continue playing?" check doesn't work as I think it should (ignoring the running/Running issue); if you answer something other than y or n it tells you that you need to give one of those choices, but doesn't ask you again and just either exits or continues, depending on whether you won or lost before.

#

Why are you setting running at all when the player wins, if you are anyways asking in the end?

#

Sure, that's understandable as a beginner. But once it works, the next step should be taking away as much as possible while keeping it working :)

pure plank
#

Perhaps something like

def choose_winner(player_choice, computer_choice):
    if player_choice == computer_choice:
        return "tie"
    elif (
        (player_choice == "r" and computer_choice == "s")
        or (player_choice == "s" and computer_choice == "p")
        or (player_choice == "p" and computer_choice == "r")
    ):
        return "player"
    else:
        return "computer

(I have an easier way to write this in mind, but paradoxically it's a bit harder to understand.)

#

Then you can call this function with the two inputs and only have to have those prints ("you won and chose X") once.

#

No, like winner = choose_winner(input1, RPS) (although I'd rename those variables)

south sundialBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.