【发布时间】:2019-05-21 03:32:23
【问题描述】:
我正在编写密码复杂度代码...我已经完成了我的程序,它说与 true 的比较应该是if cond is true: 或 if cond:,但我想不通
这是我的编程,我真的无法在其中添加或修复任何内容:
import re
print('Please copy the following: password()')
def password():
print('Make sure that your password has the following rules:')
print('1. more than 8 characters')
print('2. has a compination of uppercase and lowercase letters')
print('3. has digits')
while True:
password == input('password: ')
if password < 8:
break
print('Password must be at least 8 characters')
if re.search(r'\d', password):
if re.search(r'\d', password) == True:
print('it has a digit')
else:
print('Password must contain digits')
if re.search(r'[A-Z]', password):
if re.search(r'[A-Z]', password) == True:
print('it has uppercase letters')
else:
print('Password must contain upper case letters')
if re.search(r'[a-z]', password):
if re.search(r'[a-z]', password) == True:
print('it has lowercase letters')
else:
print('Password must contain lowercase letters')
如果密码没有小写字母、大写字母、没有数字或少于 8 个字符,则应如此说明
例如,我希望 abcABC 的输出表明它必须至少为 8 个字符并且必须包含数字。
【问题讨论】:
-
您的代码到底出了什么问题?
-
只需使用
if expression,不需要if expression == True。 -
好吧,我对你的问题一无所知......你已经在测试几个代码是否正确......你写了那一堆代码吗?
-
它是说与true的比较应该是
if cond is true:或if cond: -
在这种情况下实际上是一样的。
标签: python python-3.x ipython