Python实现用户登录问候

栏目: Python · 发布时间: 6年前

内容简介:Python创建一个至少包含 5个用户名的列表,且其中一个用户名为 'admin' 。想象你要编写代码,在每位用户登录网站后都打印一条问候消息。遍历用户名列表,并向每位用户打印一条问候消息。添加一条 if 语句,检查用户名列表是否为空。1、如果为空,就打印消息“We need some users!”。

Python创建一个至少包含 5个用户名的列表,且其中一个用户名为 'admin' 。想象你要编写代码,在每位用户登录网站后都打印一条问候消息。

遍历用户名列表,并向每位用户打印一条问候消息。添加一条 if 语句,检查用户名列表是否为空。

1、如果为空,就打印消息“We need some users!”。

2、删除列表中的所有用户名,确定将打印正确的消息。

3、如果用户名为 'admin' ,就打印一条特殊的问候消息,如“Hello admin, would you like to see a status report?”。

4、否则,打印一条普通的问候消息,如“Hello sir, thank you for logging in again”。

# !/usr/bin/env python

# -*- coding:utf-8 -*-

方法一:

usrs = ['root','administrator','admin','ming','hong','guo']

if usrs:

for usr in usrs:

if usr == 'admin':

print('Hello admin,would you like to see a report?')

else:

print('Hello sir,thank you for logging in again.')

else:

print('we need some usrs.')

方法二:if len(usrs) == 0:

print('we need some usrs.')

else:

for usr in usrs:

if usr == 'admin':

print('Hello admin,would you like to see a report?')

else:

print('Hello sir,thank you for logging in again.')

更多 Python 相关信息见 Python 专题页面 https://www.linuxidc.com/topicnews.aspx?tid=17

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

本文永久更新链接地址: https://www.linuxidc.com/Linux/2019-03/157383.htm


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Powerful

Powerful

Patty McCord / Missionday / 2018-1-25

Named by The Washington Post as one of the 11 Leadership Books to Read in 2018 When it comes to recruiting, motivating, and creating great teams, Patty McCord says most companies have it all wrong. Mc......一起来看看 《Powerful》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具