通过Python编写一个简单登录功能过程解析

yipeiwu_com6年前Python基础

需求:

写一个登录的程序,

1、最多登陆失败3次

2、登录成功,提示欢迎xx登录,今天的日期是xxx,程序结束

3、要检验输入是否为空,账号和密码不能为空

4、账号不区分大小写

import datetime
count = 0
while count < 3:
  username = input("username: ")
pwd = input("password: ")
date = datetime.date.today()
if username.strip() == ""
or pwd.strip() == "":
  print("您输入的是空值,请重新输入")
count = count + 1
continue
elif username == "shenxianlu"
and pwd == "123456":
  print("%s,欢迎您登录,今天日期是:%s" % (username, date))
break
else :
  print("输入的账号密码有误请重试")
count = count + 1
else :
  print("您的三次机会已经用完,无法继续输入")

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python中enumerate() 与zip()函数的使用比较实例分析

本文实例讲述了python中enumerate() 与zip()函数的使用比较。分享给大家供大家参考,具体如下: enumerate() 与zip()是两个常用的内置函数,这两个函数功能...

用python求一重积分和二重积分的例子

首先是对一元函数求积分,使用Scipy下的integrate函数: from scipy import integrate def g(x): return (1-x**2)**...

python得到单词模式的示例

python得到单词模式的示例

如下所示: def getWordPattern(word): pattern = [] usedLetter={} count=0 for i in word: if i...

django连接oracle时setting 配置方法

下一步是将新创建的应用程序与项目相关联。为此,您需要编辑 myproj 文件夹中的 settings.py 文件,将字符串“myproj.myapp”追加到 INSTALLED_APPS...

python中redis查看剩余过期时间及用正则通配符批量删除key的方法

具体代码如下所示: # -*- coding: utf-8 -*- import redis import datetime ''' # 1. redis设置过期时间的两种方式 e...