【问题标题】:Areas of code not functioning?代码区域不起作用?
【发布时间】:2017-06-05 20:01:57
【问题描述】:

代码:

#Welcome the user to the application.
print("Hello, please enter a password with a minimum of six characters and a max of twelve.");

#Set a variable called MinPass and set a value of 6.
MinPass = 6;

#Set a variable called MaxPass and set a value of 12.
MaxPass = 12;

#Set variable EnteredPass and wait for user input
EnteredPass = input("Password: ");

while len(EnteredPass) < MinPass:
    print("Your password is too short, please enter a longer password and try again")
    EnteredPass = input("Password: ");

while len(EnteredPass) > MaxPass:
    print("Your password is too long, please shorten it and try again!");
    EnteredPass = input("Password: ");
else:
  print("Accepted!")

  while EnteredPass.isdigit:
    print("Needs letters");
    EnteredPass = input("Password: ");

if EnteredPass.isalpha:
  print("Needs numbers")
  EnteredPass = input("Password: ")

问题:

当我运行程序并输入“错误”的东西时,它总是运行相同的功能,我不知道为什么!

【问题讨论】:

  • 这不是C++,你不需要用;终止行
  • 不要限制密码长度,你会散列密码所以你不需要限制这个。
  • stuart ---我必须这样做,这是为了课程作业。

标签: python if-statement printing while-loop passwords


【解决方案1】:

你需要真正调用你的函数

if EnteredPass.isalpha():

而不是

if EnteredPass.isalpha:

后者只是将函数对象隐式转换为bool,这将始终导致True

【讨论】:

  • 与.isdigit相同。
猜你喜欢
  • 1970-01-01
  • 2020-04-10
  • 2014-08-02
  • 1970-01-01
  • 2015-02-07
  • 1970-01-01
  • 1970-01-01
  • 2015-12-09
  • 1970-01-01
相关资源
最近更新 更多