You'll need to break out of each loop separately, as people have mentioned in the comments for your question, break only stops the loop which it's in
for x in userpassword[k]:
for z in lowercaselist:
if x in z:
newpasswordlist.append(z)
k +=1
break
if x in z: # added an extra condition to exit the main loop
break
You'll need to do this for both loops. If you want to break out of the while loop as well, then you can add if x in z: break in that loop as well.
Quite a number of my fellow teachers have been saying that we should NEVER use breaks in loops. However in our examination there is often a need to validate an input e.g.
while True:
ID = input("What is the cow's ID code?")
if len(ID) == 3:
CowID.append(ID)
break
else:
print("Cow ID has been entered wrongly.")The break works perfectly well in Python, but it has been suggested to me that I avoid using such constructs. What are your thoughts on this and does anyone have credible sources one way or another? In the age of the Internet my students will quickly find break and I would need a very strong argument as to why they don't use it. Equally, if I go against these other teachers I will need credible evidence as to why I am doing it this way.
Your thoughts, arguments and ideas are very much appreciated. This debate has been rumbling on already for over a month and I would like to get a good answer before I plan next year's lessons.