因此,我试图做出一个登录提示,我希望只有在没有错误的情况下才打印“Success”。这是我正在使用的代码:
if not is_email(email) or not is_name(name) or password != confirmPassword or not is_secure(password):
if not is_email(email):
print('Not a valid email')
if not is_name(name):
print('Not a valid name')
if password != confirmPassword:
print('Passwords don\'t match')
if not is_secure(password):
print('Password is not secure')
else:
print('Success')
有没有办法缩短代码?我想让它一次显示所有的错误,所以我不使用elif
避免重复测试的一种方法:
它不短,但清晰,节省了额外的比较,因此速度更快,不浪费时间
一种方法是使用标志:
这个怎么样
相关问题 更多 >
编程相关推荐