-3

I have a list of users on the list and want to print for them some greetings but if I have in this list I should print some another text Hello Admin, would you like to see a status report?. Also I want to have some notification if the list is empty but I don't know how to do this.

users_site = []
for site in users_site:
    if site == 'Admin':
        print ("Hello Admin, would you like to see a status report?")
    if site == []:
        print ("We need more user's")
    else:
        print (f"Hello, {site}")
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
  • `if not list` will check if a list is empty. – B Remmelzwaal Jan 31 '23 at 19:39
  • I'm assuming you want to know if `users_site` is empty, not `site` (which is presumably always a string, not a `list`)? It's still unclear why you'd write a loop though; why are you testing multiple possible usernames like this? Normally they'd provide a *single* user name and you'd check if it was recognized. – ShadowRanger Jan 31 '23 at 19:40
  • I have a list with names, which will be change or could be empty, but also in this list could be Admin and for all of this three options I need a separate notification. If I have in this list name - Hello (name), if in list Admin - Hello Admin, would you like to see a status report?, if a list is empty - We need more user's – Borys Zhyhalo Jan 31 '23 at 19:49

2 Answers2

0

Normally, I'd put everything into a function and short-circuit it early with return - you can detect if a list is empty with not which will see if the right side is Falsey

def my_function(my_list):
    if not my_list:
        print("the list is empty")
        return
    for entry in my_list:
        ...
ti7
  • 16,375
  • 6
  • 40
  • 68
0

Does this help?

users_site = ['']

if not users_site:
    print ("We need more user's")
 
else:
    
    for site in users_site:
        if site == 'Admin':
            print ("Hello Admin, would you like to see a status report?")
            
        else:
            print (f"Hello, {site}")
band
  • 129
  • 7