【问题标题】:Python GCSE homework help - passwordPython GCSE作业帮助-密码
【发布时间】:2016-05-11 16:44:19
【问题描述】:

对于我的家庭作业,我需要在 python 中创建一个用户注册系统。我需要设置密码部分。

我该做什么?

这是我的代码,我无法找出问题所在:

password = input("Please enter your password: ")
passwordl = len(password)
while passwordl <= 8:
    print("password must be more than 8 characters - please try agian")
    password = input("Please enter your password: ")
passworda = password.isalpha()
passwordi = password.isdigit()
while passworda != True or passwordi != True:
    print("password needs to contain digits and characters - please re-enter")
    password = input("Please enter your password: ")

代码在一个函数中。

谢谢

【问题讨论】:

  • 你有什么问题?...因为我一眼就能看出一些问题..
  • 请不要将文字作为图片发布。将文本复制并粘贴到您的问题中。图像不可搜索,也无法通过屏幕阅读器为有视力障碍的人解读。使用edit 链接修改您的问题。

标签: python function if-statement while-loop


【解决方案1】:

而不是跟随

 Password = input("Please enter your password")

在最后一个while循环中再次检查你最好只调用密码函数,因为它更有效。

【讨论】:

    【解决方案2】:

    如果字符串中的所有成员分别是字母数字和数字,则函数isalpha()isdigit()返回true。

    您需要做的是检查字符串中的 any 个字符是否具有正确的属性,例如:

    passworda = any([x.isalpha() for x in password])
    passwordi = any([x.isdigit() for x in password])
    

    此外,每次重新输入密码时,您都需要重做所有检查(长度和字符集检查)。

    【讨论】:

      猜你喜欢
      • 2011-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多