21 lines
555 B
Python
21 lines
555 B
Python
def input_password():
|
||
|
||
# 1\. 提示用户输入密码
|
||
pwd = input("请输入密码:")
|
||
|
||
# 2\. 判断密码长度,如果长度 >= 8,返回用户输入的密码
|
||
if len(pwd) >= 8:
|
||
return pwd
|
||
|
||
# 3\. 密码长度不够,需要抛出异常
|
||
# 1> 创建异常对象 - 使用异常的错误信息字符串作为参数
|
||
ex = Exception("密码长度不够")
|
||
|
||
# 2> 抛出异常对象
|
||
raise ex
|
||
|
||
try:
|
||
user_pwd = input_password()
|
||
print(user_pwd)
|
||
except Exception as result:
|
||
print("发现错误:%s" % result) |