在为完成练习5-8编写的程序中,添加一条if语句,检查用户名列表是否为空。
□如果为空,就打印消息“We need to find some users!”。
□删除列表中的所有用户名,确定将打印正确的消息。
代码:
names=['admin','eric','mike','susan','judy']
if names:
for name in names:
if name=='admin':
print('\nHello Admin,would you like to see a status report?')
else:
print('\nHello '+name.title()+',thank you for logging in again.')
else:
print('We need to find some users.')
运行结果:
代码:
names=[]
if names:
for name in names:
if name=='admin':
print('\nHello Admin,would you like to see a status report?')
else:
print('\nHello '+name.title()+',thank you for logging in again.')
else:
print('We need to find some users.')
运行结果: