-2

I just need to add +30 to every number in every if statement. I need 36 of these, is there a way to let turtle make more if statements or something similar? I'm really stuck and the manual way would be crazy.

For example:

if 0 <= x <=30 and 0 <= y <= 30:
      turtle.drawsstuff

if 30 <= x <=60 and 0 <= y <= 60:

etc.

2 Answers2

5

Use a for loop.

for n in range(0, 36 * 30, 30):
    if n <= x <= n + 30 and 0 <= y <= n + 30:
        pass #do something
John
  • 13,197
  • 7
  • 51
  • 101
2
for n in range(0, 36 * 30, 30):
    if n <= x <= (n+30) and n <= y <= (n+30):
        pass  # (do stuff)

range can take an optional third argument for the "step" value. For reference, see Python's documentation on range.

tckmn
  • 57,719
  • 27
  • 114
  • 156