如何解决密码的新if函数
对于我的新学习,我需要创建一个新函数new_password(),该函数具有2个参数:oldpassword和newpassword。密码符合要求时,返回值必须为True。仅当新密码与旧密码不同且至少包含6个字符时,才接受新密码。如果不是,则返回值必须为False。
我是python的新手,因此将不胜感激。 这就是我到目前为止所得到的:
def new_password(oldpassword,newpassword):
if(oldpassword == newpassword and newpassword < 6):
return false
else:
return true
解决方法
您可以这样做:
def new_password(oldpassword,newpassword):
return (oldpassword != newpassword and len(newpassword) >= 6)
布尔值(True
和False
)在python中以大写字母btw开头。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。