Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with an if statement
#1
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:

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
Reply


Messages In This Thread
Help with an if statement - by stylingpat - Feb-25-2021, 10:17 PM
RE: Help with an if statement - by eddywinch82 - Feb-25-2021, 10:59 PM
RE: Help with an if statement - by bowlofred - Feb-25-2021, 11:00 PM
RE: Help with an if statement - by eddywinch82 - Feb-25-2021, 11:12 PM
RE: Help with an if statement - by stylingpat - Feb-26-2021, 01:05 AM
RE: Help with an if statement - by nilamo - Mar-03-2021, 10:05 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020