m0_58505228 2021-05-22 03:23 采纳率: 62.5%
浏览 65
已采纳

Python函数题目

定义一个名为“ isStrongPassword”的函数,该函数将字符串作为参数。功能然后将检查所提供的字符串是否满足以下条件,以检查是否为强 密码: 1.必须至少包含1个大写和小写字母的组合 2.必须至少包含3位数字 3.必须至少包含3个特殊字符(包括空格) 4.密码长度必须至少12个字符 该函数将返回一个布尔值,即如果满足所有条件则返回True或返回False 除此以外。 确保使用可能返回False值的每个可能的输入来测试函数也一样

  • 写回答

4条回答 默认 最新

  • benbenli 2021-05-22 03:51
    关注
    
    def isStrongPassword(pwd):
        chars = list(pwd)
        upper = [c for c in chars if 'A' <= c and c <= 'Z']
        lower = [c for c in chars if 'a' <= c and c <= 'z']
        digit = [c for c in chars if '0' <= c and c <= '9' ]
        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')] 
        strong = len(upper) >= 1 and len(lower) >= 1 and len(digit) >= 3 and len(symbol) >= 3 and len(pwd) >= 12
        return strong
        
        
        
    print(isStrongPassword("Str0n9P@$$w0rd"))
    print(isStrongPassword("StrongPassword"))
    print(isStrongPassword("Stron9P@$$0rd"))
    print(isStrongPassword("Str0n9Pass0rd"))
    print(isStrongPassword("str0n9p@$$0rd"))
    print(isStrongPassword("Str0n9P@$$"))
    print(isStrongPassword("12345678"))
    print(isStrongPassword("~!@#$%^&*()_+"))
    print(isStrongPassword("STRONGPASSWORD"))
    
    
    # output
    True
    False
    False
    False
    False
    False
    False
    False
    False
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch