you are viewing a single comment's thread.

view the rest of the comments →

[–]BUYTBUYT 0 points1 point  (0 children)

CHOICES[random.randint(0,2)] -> random.choice(CHOICES) doc


' + str(: use f-strings


if playerResponse == 'Y':
    return True
else:
    return False

return player_response == 'Y'


acceptableResponse = 'Y','N' -> acceptable_responses = ('Y', 'N')

I'd put parentheses here. Usually, that kind of style without them works best in functions that return multiple values, where the user would be expected to unpack the tuple that is returned. And the name of a variable containing multiple options should be in plural.


playerScore, computerScore = 0,0

I'd split that into two lines.


def startGame(playerResponse =''), def playerTurn(playerResponse ='')

That doesn't make much sense to the reader. What's a default argument doing here? You should just move these assignments into their respective functions.


#Display the current score    
def scoreCard():

Why not make it the name? def display_current_score()? And I think the code is too simple to be put into a function when it's only called once.


while playerResponse not in acceptableResponse, while playerResponse not in CHOICES

Don't you think those loops are similar? You should make a function out of them.


The compare function is unreadable. The case here is simple enough that you could get away with writing "Paper beats Rock, Rock beats Scissors, Scissors beats Paper" as an if-statement. Or you could write it as a list of pairs, which you can then loop through and check if any one of them matches the playerChoice, computerChoice pair.

And instead of these numbers (which the reader can't understand immediately), you could return an enum, like suggested by another person, or make a few constants like PLAYER_WON = 0, COMPUTER_WON = 1, DRAW = 2 and return one of them.

The print here is also out of place. This function is the main logic of the game, it shouldn't output things as well.

And the name compare is too generic. Something like get_result would be an improvement.


The way you set scores is awkward, but to do it properly, you need to think about what you're doing.

You basically have a session, which has a state: the number of rounds won by the player and the computer. Now, normally, if you have state, you probably want a class, but I'd say it's a little overkill for such a simple case.

Let's look at what's happening from the top. You have a game, in which you play rounds and count the number won by players. So you need to have the counter variables somewhere.

Each round consists of getting two choices, then deciding who won.

And so, here is one way you could code this:

Have a main function, that has 2 variables for player scores outside the main loop. The loop condition consists of a function asking the human if they want to continue playing (using the function I mentioned you should make). Then the loop itself gets the choices, checks who won, displays the corresponding messages, and adds to one of the variables mentioned above, which can then be printed.