Heres the following code:
while True:
if turtle.xcor() >= 350 or <= -350:
print 'yes'
it always prints 'yes'
help?
Heres the following code:
while True:
if turtle.xcor() >= 350 or <= -350:
print 'yes'
it always prints 'yes'
help?
change
if turtle.xcor() >= 350 or <= -350: #this has a syntax error
to
if turtle.xcor() >= 350 or turtle.xcor() <= -350:
or
if abs(turtle.xcor()) >= 350: # thanks – @vaultah
or
if not 350 <= turtle.xcor() >= -350: # thanks - @jonrsharpe
Your code should not print anything as there is a syntax error.
You could write
while True:
if not (-350 < turtle.xcor() < 350):
print 'yes'
See Python documentation for this shortcut notation, which is seldom found in other languages. Also while the parentheses are not required in this case (see operator precedence), I think they add some clarity to the expression.