Aug-29-2024, 03:39 AM
(This post was last modified: Aug-29-2024, 07:16 AM by Gribouillis.)
Hi,
I am learning Python by studying and doing exercises. Currently I am programming a Tictactoe game as an exercise. it includes the following code snippet:
Thank You
swgeel
I am learning Python by studying and doing exercises. Currently I am programming a Tictactoe game as an exercise. it includes the following code snippet:
def GetMove(player): # Get move for Current Player # Clear the Terminal Clear() # Print Game Title Title() #Print the Current Board PrintCurrBoard() #Show the Moves available to the current player Choices() move=input("\nPlayer {} Please enter the move of your choice: ".format(player)) response="" response=ValidMove(move,player) while not response: TryAgain="" TryAgain=input("That is an Invalid move - Would you like to try again to Continue the Game \ (Y or N)\n\n") while TryAgain != "": # I realize I have to change this statement, it is not what I am working on now. GetMove(player)Now, the above code functions as it is supposed to / correctly, however the <while not response"> was originally written as
while response =="False":functionally, when written that way, the while loop will only functions if response is actually set equal to false, rather than being set to the return of the ValidateMove function (which is returning True or False, as appropriate). This I do not understand as
while not response:and
While response == "False":should be logically equivalent and function in an identical fashion. Help a noob out and explain why my logic seems to be functioning differently than python's.

Thank You
swgeel
Gribouillis write Aug-29-2024, 07:16 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.