2

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?

jathanism
  • 33,067
  • 9
  • 68
  • 86
  • 1
    I don't know what language this is in. You should add it as a tag. – Nikos C. Oct 22 '12 at 00:12
  • 1
    Wild guess as I don't even recognize the language this is, but shouldn't there be some variable name just before the `>` ? And maybe some () to make things a lot more readable? – fvu Oct 22 '12 at 00:12

4 Answers4

6

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

if variable - 2.0 / 3 < x <= variable / 3:
    # ...
Blender
  • 289,723
  • 53
  • 439
  • 496
2

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.

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
1

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.

emschorsch
  • 1,619
  • 3
  • 19
  • 33
0

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'
agirish
  • 473
  • 4
  • 9