I need your help. I got into learning python and having learnt some theory, I decided to try my hands on something simple(a code which compares its result to the value to a given variable). I have a variable 'pin' and assigned a list of numbers to it. Then I created another variable 'numArray' and also assigned a list to it. Another variable 'access' with a empty list assigned. Now, I have nested 'for loops' which iterate through the 'numArray' and the result is reassigned to the 'access' variable and then 'access' gets printed out every time. Next, I compare 'access' with 'pin' and if both are the same, then a statement is printed and the loop should be exited. Everything seems to work fine up to this point. Instead of the loop ending at {0,4,5,6], it gets there, prints the statement, skips - [0,4,5,7],[0,4,5,8],[[0,4,5,9] - and continues the loop from [0,4,6,0].
I know I am doing something wrong but I cannot figure out what it is. I would be glad if anyone can help me find what the issue is or even how to write this in a more efficient way as I plan to expand on this as my knowledge progresses. By the way, I am just practicing how to use conditionals and loops. Thanks in advance.
import time
pin = [0,4,5,6]
numArray = [0,1,2,3,4,5,6,7,8,9]
found = True
access = []
while found:
for p1 in numArray:
for p2 in numArray:
for p3 in numArray:
for p4 in numArray:
access = [p1,p2,p3,p4]
time.sleep(0.01)
print(access)
if access == pin:
print('Access Granted - The pin is:', access)
found = False
break
else:
continue