-1

I would like to specify range restrictions for multiple variables in Python code.

I have tried troubleshooting on pythontutor.com to no success.

for i in range (0,5), j in range (1,2):
    d=(abs(a[i]-(c+j)/(s+1)))
    z.append(d)

Error:

NameError: name 'j' is not defined
Austin
  • 25,759
  • 4
  • 25
  • 48

1 Answers1

2

I think you want a nested for loop:

for i in range(2):
    for j in range(2):
        print(i, j)

Output:

0 0
0 1
1 0
1 1

Otherwise you might want zip():

for i, j in zip(range(2), range(2)):
    print(i, j)

Output:

0 0
1 1
wjandrea
  • 28,235
  • 9
  • 60
  • 81