-4

Heres the following code:

while True:
    if turtle.xcor() >= 350 or <= -350:
        print 'yes'

it always prints 'yes'

help?

A Display Name
  • 367
  • 1
  • 9
  • 18

2 Answers2

3

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
Donat Pants
  • 379
  • 4
  • 11
0

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.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
rto32
  • 36
  • 5