Assigning variable in if-statement


Please leave the following link in the post so we can find the unit module, else replace it with a link to the exact lesson:

Strings and Console Output

Hello! I’m trying to make a Tic Tac Toe game and I’ve just built a board. Now I need to assign a marker (“x”, or “o”), as a result of the 1st player’s input.

I’ve written the code like this:

choice = input('Player 1, choose whether to be "x" or "o"\n> ')

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

print(f"Player 1 will be {player1} and Player2 will be {player2}")

but it turns out to be a mistake. How can I assign variables in an if statement?
Have a good day


the and operator is used to see if multiple conditions are true, like in a if condition or the condition of a while loop

you can’t use it to declare two variable on the same line

if you don’t know, just declare each variable on its own line


Thanks a lot! Problem solved :slight_smile: