I have the following code using the comprehensive list:
x = int ( input())
y = int ( input())
z = int ( input())
n = int ( input())
ret_list = [ (x,y,z) for x in range(x+1) for y in range(y+1) for z in
range(z+1) if x+y+z!=n ]
print(ret_list)
in python2 works as expected. However in python3 i get the following error:
print([ (x,y,z) for x in range(x+1) for y in range(y+1) for z in range(z+1) if
x+y+z!=n ])
File "tester.py", line 16, in <listcomp>
print([ (x,y,z) for x in range(x+1) for y in range(y+1) for z in range(z+1) if
x+y+z!=n ])
UnboundLocalError: local variable 'y' referenced before assignment
I am just curious what I am doing wrong. I might be missing something in Python3 although it works fantastic in python2. Thank you.