{ "question_id": 7433771, "question_title": "检查密码强度", "question_content": "
定义一个名为“isStrongPassword”的函数,该函数将字符串作为参数。功能然后将检查所提供的字符串是否满足以下条件,以检查是否为强 \n密码:\n1.必须至少包含1个大写和小写字母的组合\n2.必须至少包含3位数字\n3.必须至少包含3个特殊字符(包括空格)\n4.密码长度必须至少12个字符\n该函数将返回一个布尔值,即如果满足所有条件则返回True或返回False\n确保使用可能返回False值的每个可能的输入来测试函数也一样
", "difficulty": "简单", "answer_id": 53404077, "answer_content": "\n\ndef isStrongPassword(pwd):\n chars = list(pwd)\n upper = [c for c in chars if 'A' <= c and c <= 'Z']\n lower = [c for c in chars if 'a' <= c and c <= 'z']\n digit = [c for c in chars if '0' <= c and c <= '9' ]\n symbol = [c for c in chars if not ('A' <= c and c <= 'Z' or 'a' <= c and c <= 'z' or '0' <= c and c <= '9')] \n strong = len(upper) >= 1 and len(lower) >= 1 and len(digit) >= 3 and len(symbol) >= 3 and len(pwd) >= 12\n return strong\n \n \n \nprint(isStrongPassword("Str0n9P@$$w0rd"))\nprint(isStrongPassword("StrongPassword"))\nprint(isStrongPassword("Stron9P@$$0rd"))\nprint(isStrongPassword("Str0n9Pass0rd"))\nprint(isStrongPassword("str0n9p@$$0rd"))\nprint(isStrongPassword("Str0n9P@$$"))\nprint(isStrongPassword("12345678"))\nprint(isStrongPassword("~!@#$%^&*()_+"))\nprint(isStrongPassword("STRONGPASSWORD"))\n\n\n# output\nTrue\nFalse\nFalse\nFalse\nFalse\nFalse\nFalse\nFalse\nFalse
\n\n\n", "tag_name": "python", "python": "def isStrongPassword(pwd):\n\tchars = list(pwd)\n\tupper = [c for c in chars if 'A' <= c and c <= 'Z']\n\tlower = [c for c in chars if 'a' <= c and c <= 'z']\n\tdigit = [c for c in chars if '0' <= c and c <= '9' ]\n\tsymbol = [c for c in chars if not ('A' <= c and c <= 'Z' or 'a' <= c and c <= 'z' or '0' <= c and c <= '9')] \n\tstrong = len(upper) >= 1 and len(lower) >= 1 and len(digit) >= 3 and len(symbol) >= 3 and len(pwd) >= 12\n\treturn strong\nprint(isStrongPassword(\"Str0n9P@$$w0rd\"))\nprint(isStrongPassword(\"StrongPassword\"))\nprint(isStrongPassword(\"Stron9P@$$0rd\"))\nprint(isStrongPassword(\"Str0n9Pass0rd\"))\nprint(isStrongPassword(\"str0n9p@$$0rd\"))\nprint(isStrongPassword(\"Str0n9P@$$\"))\nprint(isStrongPassword(\"12345678\"))\nprint(isStrongPassword(\"~!@#$%^&*()_+\"))\nprint(isStrongPassword(\"STRONGPASSWORD\"))", "topic_link": "https://bbs.csdn.net/topics/600469891", "status": 1, "keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数", "license": "csdn.net", "notebook": { "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/37.ipynb?type=file" }, "notebook_enable": 1 }