Python 3.6 Rock-Paper-Scissors game I was asked to write a "Rock Paper Scissors" game as a practice exercise for class. I ended up with this code which works as intended. It's a one player vs. the computer game.

Overview:


Computer and player choose their 'weapons'
Decide the winner
Print the winner


Does anyone have any constructive feedback or tips on how I could improve this?

import random as r

#the possible moves in rock paper scissors
RPS = ["ROCK", "PAPER", "SCISSORS"]

def main():
    comp = computerMove()
    player = playerMove()
    winner, tie = calcWinner(comp, player)
    dispWinner(winner, tie)

#the move made by the computer
def computerMove():
   comp =  r.choice(RPS)
##   print(comp)
   return comp

#move made by the user
def playerMove():
    player = ""
    while not player in RPS:
            player = input("Choose your weapon(rock, paper, or scissors: ").upper()
##    print(player)
    return player

#determining a winner
def calcWinner(comp, player):
    print("The computer chooses {0}.".format(comp))
    winner = None
    tie = False

## if theres a tie
    if player == comp:
        print("No winner.... Restarting....\n")
        main()
        tie = True

## if the user wins        
    elif ((comp == "ROCK") and (player == "PAPER")) or ((comp=="PAPER") and (player == "SCISSORS")) or ((comp=="SCISSORS") and (player == "ROCK")):
        winner = True
## if computer won
    else:
        winner = False

    return winner, tie

def dispWinner(winner, tie):
    if tie == True:
        print("")
    elif winner == True:
        print("You beat the computer!")
    elif winner == False:
        print("The computer beat you!")


main()
First of all, welcome to codereview! It's nice to see that you are attending Python courses at University / highschool.



Styling

As you're at the beginning of the road, you should know that Python has a style-guide which is called PEP8. You can read there things like:


Naming conventions: function / variable names should be lower_cased
Comments: you should add a space after # (a single one is enough, it's not necessary to abuse it) when you comment out the code, you should avoid obvious comments and also try to write docstrings to each function
Maximum line length: lines should have a maximum length of 79 characters (this is debatable as some editors - like PyCharm suggests a maximum of 120).
Spacing: you should have two new lines between methods, and one whitespace around operators


That being said, your code after some styling might look like this:

import random as r

RPS = ["ROCK", "PAPER", "SCISSORS"]


def main():
    """This is the main function"""
    comp = computer_move()
    player = player_move()
    winner, tie = calc_winner(comp, player)
    disp_winner(winner, tie)


def computer_move():
    """The move made by the computer."""
    comp = r.choice(RPS)
    return comp


def player_move():
    """The move made by the user."""
    player = ""
    while not player in RPS:
        player = input("Choose your weapon(rock, paper, or scissors: ").upper()
    return player


def calc_winner(comp, player):
    """Determining a winner."""
    print("The computer chooses {0}.".format(comp))
    winner = None
    tie = False

    if player == comp:
        print("No winner.... Restarting....\n")
        main()
        tie = True
    elif (((comp == "ROCK") and (player == "PAPER")) or 
          ((comp == "PAPER") and (player == "SCISSORS")) or 
          ((comp == "SCISSORS") and (player == "ROCK"))):
        winner = True
    else:
        winner = False

    return winner, tie


def disp_winner(winner, tie):
    """Display the winner of the game."""
    if tie == True:
        print("")
    elif winner == True:
        print("You beat the computer!")
    elif winner == False:
        print("The computer beat you!")


main()




More about styling

Keep in mind that your comments should be succinct and explicit and should emphasise what the method does.

I usually put the main() function after the others because it comes more naturally when you read the code.

Give descriptive names to your functions / variables. Doing this will make the code speak for itself (more readable) and will make you remove unnecessary comments.

You only use random once. Don't give it an alias.



Equality vs Identity Comparisons

is is identity testing, == is equality testing.

You should use:

if tie is True:
    ...


Instead of:

if tie == True:
    ...


Or shorted:

if tie:
    ...


! Remember that if you use is, the result will be true if and only if the object is the same object. However, == will be true any time the values of the object are the same.



Testing for membership

You should write:

while player not in RPS:
    ...


Instead of:

while not player in RPS:
    ...




Tuples vs Lists

Because your RPS is not changing, I'd recommend you use a tuple instead. A couple of advantages of doing the above:


  
  Tuples are faster than lists. If you're defining a constant set of values and all you're ever going to do with it is iterate through it,
  use a tuple instead of a list.
  It makes your code safer if you “write-protect” data that does not need to be changed. Using a tuple instead of a list is like having an
  implied assert statement that this data is constant, and that special
  thought (and a specific function) is required to override that.
  




Fix the bug

If the computer chooses scissors and you choose paper there won't be any result because you only test for half of the cases.

Choose your weapon(rock, paper, or scissors: paper
The computer chooses SCISSORS.

Process finished with exit code 0


I'll let you fix this. HINT (think of a suitable data structure that can make the things easier) 

Double hint: maybe a dictionary?