program 1 : python codes for login program(登录程序python代码)

#improt time module for count down puase time
import time
#set var for loop counting
counter=1
#login setting
while counter<=3: print('please enter username: ')
username=input()
print('please enter password: ')
password=input()
#dict for username and password
userinf={
'xiaoweilai':'xiaoweilai',
'python':'',
'education':'edu123'
}
#different entering cases
if userinf.__contains__(username) and userinf.get(username)==password:
print('welcome to python world')
break
else:
print("username/password's error","please try again")
counter=counter+1
#error entering for 3 times and forcely stop 10senconds.
if counter==3:
print('You try it too much times.')
counter = 0
while counter <= 10:
print(10 - counter)
time.sleep(1)
counter = counter + 1
counter=0
continue

Read me 程序说明:

设计一个需要用户名和密码的登录程序

用户输入登录用户名和密码,后台处理用户输入的用户名和密码,即检测已有用户名和列表中有无该用户名和对应的密码是否错误。如果输入错误,继续尝试第二次,若第二次错误,继续尝试第三次,如果第三次输入错误则提示输入次数太多,并暂停输入10秒,显示10秒倒计时。倒计时结束后,继续尝试。不断循环,直至输入正确的用户名和密码。程序结束。

summary 知识点总结:

time 模块应用,字典应用,while 循环嵌套语句,break 和 continue 语句,if else 语句。

If you like, contact me. QQ 278857042  please note: python or big data.

上一篇:python视频学习笔记2(if)


下一篇:virtualbbox centos7 NAT模式外网 Host-only Adapter模式联网 双网卡