Raul Unc
Raul Unc

Reputation: 39

Function won't print anything

I am trying to get the output of this function but I can't get anything, I tried to change elements but couldn't get anything.

def player_input():

marker = " "
while marker != "x" and marker != "o":
        marker = input("Player 1, choose x or o: ")

        player1 = marker

        if player1 == "x":
            player2 = "o"

        else:
            player2 = "x"

print(player_input)

Upvotes: 0

Views: 128

Answers (1)

joshLor
joshLor

Reputation: 1074

You mussed do two things:

  1. add opening and closing brackets when you are calling the function so change print(player_input) to print(player_input()). This runs the function rather than simply printing a pointer to the function.

  2. to get the value of a variable from a function you must return that value. So add the line return player2, for instance, if you want to get the value of the variable player2 when calling the function.

Upvotes: 1

Related Questions