含len()的if语句未执行:Python密码验证程序异常排查
编辑:此问题由Python/IDE安装故障导致,重装IDE后代码运行正常。
我编写了一个简单的密码设置程序,要求用户两次输入密码,若两次输入一致则提示“Password set.”。但问题在于,程序跳过了检查密码长度需在8-12字符之间的第一个if语句,希望了解该问题的原因。
程序代码
pswrd = input('Please choose a password: ') if len(pswrd) < 8 or len(pswrd) > 12: print('The password you have chosen is invalid. Please create a password between 8-12 characters.') else: pswrd2 = input('Please retype your new password for confirmation: ') if pswrd2 == pswrd: print('Thank you. Your password has been set.') else: print('Your two entries do not match. Please try again.')
程序输出
Please choose a password: seven Please retype your new password for confirmation: seven Thank you. Your password has been set. Process finished with exit code 0
如您所见,程序未识别到密码长度不足8字符,这是为什么?
内容的提问来源于stack exchange,提问作者veryconfused
相关产品推荐
相关产品推荐

