Jun-14-2020, 04:58 PM
usernames = [] for username in usernames: if username == 'admin': print("Hello admin, would you like a status report?") if username != 'admin': print("Hello " + username + ", thank you for logging in again!") else: print("We need more users!")It has to be
else
related to the for
loop, not as part of if
.`else
part of the loop is executed if no break
statement is hit inside the loop.Note that it doesn't make sense to iterate over users in the list - if the list is not empty it will print something for every user in the list and again will print the else part (because there is no break inside the loop)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs