Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double variable if statement not working

I'm making a double variable if statement and it keeps returning an error. I don't know what's wrong:

variable = float(0)

for index in range(10):

    variable = variable + float(2)

    if x <= float(variable/3) and > float(variable-2.0/3):
        # do something

    else:
        pass

or something like that. This is the basic structure. Why does it keep highlighting the > in red whenever I try to run it?

like image 529
Felis Vulpes Avatar asked Mar 06 '26 06:03

Felis Vulpes


2 Answers

Python supports regular inequalities as well, so you could just write this:

if variable - 2.0 / 3 < x <= variable / 3:
    # ...
like image 142
Blender Avatar answered Mar 08 '26 20:03

Blender


You want to do something like

if ((x <= float(variable/3)) and (x > float(variable-2.0/3))):
       # do something

 else:
       pass

In other words, each side of the and must be a boolean expression on its own. I'm not sure whether you need all the parenthesis.

like image 38
Chris Gerken Avatar answered Mar 08 '26 21:03

Chris Gerken



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!