提示用户输入密码
def input_passwd():
# 1.提示用户输入密码
pwd=input('请输入密码:')
# 2.判断密码长度 密码长度必须是8位或8位以上
if len(pwd)>=8:
return pwd
# 3.如果密码长度<8,就主动抛出异常
# 创建异常对象
ex=Exception('密码长度不够,必须大于8位')
# 4.主动抛出异常
raise ex
# 注意:只抛出而不捕获,代码会出现异常
try:
print(input_passwd())
except Exception as re:
print(re)