创建一个至少包含5个用户名的列表,且其中一个用户名为 admin’。想象你要編写代码,在每位用户登录网站后都打印一条问候消息。遍历用户名列表,并向每位用户打印一条问候消息: 如果用户名为'admin,就打印一条特殊的问候消,息,如Hello admin, would you ike to see a status report?。 否则.打印一条昔通的问候消息,如Hello Eric, thank you for logging in again。 输出 Hello eric, thank you for logging in again! Hello willie, thank you for logging in again! Hello admin, would you like to see a status report? Hello erin, thank you for logging in again! Hello ever, thank you for logging in again!
时间: 2024-02-20 11:01:07 浏览: 84
PLSQL14_32位
好的,以下是Python代码实现:
```
usernames = ['eric', 'willie', 'admin', 'erin', 'ever']
for username in usernames:
if username == 'admin':
print('Hello admin, would you like to see a status report?')
else:
print('Hello ' + username.title() + ', thank you for logging in again!')
```
输出结果为:
```
Hello Eric, thank you for logging in again!
Hello Willie, thank you for logging in again!
Hello admin, would you like to see a status report?
Hello Erin, thank you for logging in again!
Hello Ever, thank you for logging in again!
```
阅读全文