Feb-25-2021, 10:17 PM
I’m working through my Python Crash Course book and building one of the “try it yourself” tests.
I don’t understand why the username Admin is being printed in the else statement?
I’m trying to have Admin and Moderator print their own special messages and the other users get the generic ones.
Here is the code:
I don’t understand why the username Admin is being printed in the else statement?
I’m trying to have Admin and Moderator print their own special messages and the other users get the generic ones.
Here is the code:
usernames = ["cozzie", "stylingpat", "lilly25", "moderator", "admin"] if usernames: for username in usernames: if "admin" in username: print(f"Hello {username}, would you like a status report?") if "moderator" in username: print(f"Hello {username}, would you like the server messages?") else: print(f"Hello {username}, welcome to the server!") else: print("We need to find some users!")And here is the output I am getting:
Output:
Hello cozzie, welcome to the server!
Hello stylingpat, welcome to the server!
Hello lilly25, welcome to the server!
Hello moderator, would you like the server messages?
Hello admin, would you like a status report?
Hello admin, welcome to the server!
Any advice? Thank you