# 1. 设计一个函数,对用户名和密码的格式进行校验 # * 将键盘输入的数据作为函数参数传入 # * 用户名长度6-20,且必须以字母开头 # * 密码长度至少6位,不能为纯数字,不能有空格 def accpwd(acc,pwd): lenacc = len(acc) if lenacc in [x for x in range(6,21)] and acc[0].isalpha(): print('用户名输入正确') else: print('用户名输入错误') return lenpwd = len(pwd) if lenpwd <=6: if not pwd.isdigit(): for pwdspace in pwd: if not pwdspace == ' ': print('密码正确') return else: print('密码中不能有空格') return else: print('密码不能为纯数字') return else: print('密码长度至少为6位') return acc = input('请输入用户名:') pwd = input('请输入密码:') accpwd(acc,pwd)
简单密码校验
最新推荐文章于 2023-08-12 14:28:30 发布