Reputation: 25
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?
Upvotes: 2
Views: 1103
Reputation: 470
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'
Upvotes: 0
Reputation: 298136
Python supports regular inequalities as well, so you could just write this:
if variable - 2.0 / 3 < x <= variable / 3:
# ...
Upvotes: 6
Reputation: 1669
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.
Upvotes: 1
Reputation: 16392
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.
Upvotes: 2