陕西长城建设工程有限公司网站,功能网站首页模板,长春旅游网站开发,天元建设集团有限公司 伊永成CheckiO 是面向初学者和高级程序员的编码游戏#xff0c;使用 Python 和 JavaScript 解决棘手的挑战和有趣的任务#xff0c;从而提高你的编码技能#xff0c;本博客主要记录自己用 Python 在闯关时的做题思路和实现代码#xff0c;同时也学习学习其他大神写的代码。
Chec…
CheckiO 是面向初学者和高级程序员的编码游戏使用 Python 和 JavaScript 解决棘手的挑战和有趣的任务从而提高你的编码技能本博客主要记录自己用 Python 在闯关时的做题思路和实现代码同时也学习学习其他大神写的代码。
CheckiO 官网https://checkio.org/
我的 CheckiO 主页https://py.checkio.org/user/TRHX/
CheckiO 题解系列专栏https://itrhx.blog.csdn.net/category_9536424.html
CheckiO 所有题解源代码https://github.com/TRHX/Python-CheckiO-Exercise 题目描述
【House Password】斯蒂芬和索菲亚对于一切都使用简单的密码忘记了安全性。请你帮助尼古拉开发一个密码安全检查模块。如果密码的长度大于或等于10个字符且其中至少有一个数字、一个大写字母和一个小写字母该密码将被视为足够强大。密码只包含ASCII拉丁字母或数字。
【链接】https://py.checkio.org/mission/house-password/
【输入】密码字符串类型
【输出】密码的安全与否True 或 False
【前提】re.match([a-zA-Z0-9], password) 0 len(password) ≤ 64
【范例】
checkio(A1213pokl) False
checkio(bAse730onE) True
checkio(asasasasasasasaas) False
checkio(QWERTYqwerty) False
checkio(123456123456) False
checkio(QwErTy911poqqqq) True解题思路
利用 Python 的 re 库用 search() 方法扫描整个字符串如果包含一个数字、一个大写字母和一个小写字母并且整个字符串长度大于或等于10个字符则输出 True否则输出 False
代码实现
import redef checkio(data: str) - bool:if re.search(r[0-9], data) and re.search(r[a-z], data) and re.search(r[A-Z], data) and len(data) 10:return Trueelse:return False# Some hints
# Just check all conditionsif __name__ __main__:# These asserts using only for self-checking and not necessary for auto-testingassert checkio(A1213pokl) False, 1st exampleassert checkio(bAse730onE4) True, 2nd exampleassert checkio(asasasasasasasaas) False, 3rd exampleassert checkio(QWERTYqwerty) False, 4th exampleassert checkio(123456123456) False, 5th exampleassert checkio(QwErTy911poqqqq) True, 6th exampleprint(Coding complete? Click Check to review your tests and earn cool rewards!)大神解答 大神解答 NO.1 import redef checkio(data):return True if re.search(^(?.*\d)(?.*[a-z])(?.*[A-Z]).*$, data) and len(data) 10 else False大神解答 NO.2 flambda d,x:any(ord(t)96x for t in d)
checkiolambda d:f(d,32)f(d,64)f(d,96)(len(d)9)原谅我能力不够看不懂大神写的这代码是啥意思 大神解答 NO.3 checkiolambda s:len(s)9and all(any(f(c)for c in s)for f in[str.isdigit,str.isupper,str.islower])