QUESTION IMAGE
Question
- make a list of five or more usernames, including the name admin. imagine you are writing code that will print a greeting to each user after they log into a website. loop through the list and print a greeting to each user:
a) if the username is admin, print out a special greeting, such as hello admin, would you like to see a status report?
b) otherwise, print a generic greeting, such as hello eric, thank you for logging in again.
c) add an if test to make sure your list is not empty. if the list is empty, print out the message we need to find some users! note: remove all usernames from your list in order to print out this last message
Step1: Create the list of usernames
usernames = ['admin', 'user1', 'user2', 'user3', 'user4']
Step2: Check if the list is empty
if usernames:
for username in usernames:
if username == 'admin':
print(f"Hello {username}, would you like to see a status report?")
else:
print(f"Hello {username}, thank you for logging in again.")
else:
print("We need to find some users!")
Step3: Remove all usernames to test the empty list case
usernames = []
if usernames:
for username in usernames:
if username == 'admin':
print(f"Hello {username}, would you like to see a status report?")
else:
print(f"Hello {username}, thank you for logging in again.")
else:
print("We need to find some users!")Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
When the list is not empty:
Hello admin, would you like to see a status report?
Hello user1, thank you for logging in again.
Hello user2, thank you for logging in again.
Hello user3, thank you for logging in again.
Hello user4, thank you for logging in again.
When the list is empty:
We need to find some users!