Elan JM
Elan JM

Reputation: 1

Python3 boolean if statement

while True:

   x = False

   if x == False:
     if (float) <= (price):
        if not safe_mode:
            (Some function)
     x = True
     print(something)

   elif x == True:
     if (float) >= (price):
        if not safe_mode:
            (Some Function)
     x = False
     print(something)

that is my code, and i want that to loop, but what i get is 'x' doesn't want to change value to 'True'... and 'x = True' get grayed out. I don't know why it doesn't want to work, i need all your help pls. i kinda stress finding the problem :(

Upvotes: 0

Views: 715

Answers (1)

Henry Woody
Henry Woody

Reputation: 15662

The problem is that you set x back to False at the beginning of each iteration of the while loop, so its value is changed within each conditional block, but then changed back to False right after when the loop starts over.

Just set x = False outside of the while loop and that'll solve it. Example:

x = False

while True:
    # do stuff

Upvotes: 5

Related Questions