5-8 以特殊方式跟管理员打招呼
users = ['admin', 'alice', 'bob', 'carlos', 'david']
for user in users:
if user == 'admin':
print("Hello admin, would you like to see a status report?")
else:
print("Hello " + user + ", thank you for logging in again.")
5-9 处理没有用户的情形
users = []
if users:
for user in users:
if user == 'admin':
print("Hello admin, would you like to see a status report?")
else:
print("Hello " + user + ", thank you for logging in again.")
else:
print("We need to find some users!")
5-10 检查用户名
current_users = ['alice', 'bob', 'carmen', 'david', 'eric']
new_users = ['Alice', 'david', 'ford', 'gloria', 'harris']
for user in new_users:
if user.lower() in current_users:
print(user + " have been used.Please create a new name.")
else:
print(user + " is not be used.")
5-11 序数
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for number in numbers:
if number == 1:
print("1st")
elif number == 2:
print("2nd")
elif number == 3:
print("3rd")
else:
print(str(number) + "th")