Double variable if statement not working

1k views Asked by At

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?

4

There are 4 answers

0
Chris Gerken On

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.

0
emschorsch On

It seems like you're missing a variable or constant before the second condition in the if-block. That might be one reason you're getting an error.

0
Blender On

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

if variable - 2.0 / 3 < x <= variable / 3:
    # ...
0
agirish On

This code works fine:

index=0

x=0
variable = float(0)
for index in range(10):
variable=variable + float(2)

if x <= float(variable/3) and x> float(variable-2.0/3):
    print 'Doesn\'t Matter'
else:
    print 'pass'