代码:
#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: ")
问题:
当我运行程序并输入“错误”的内容时,它总是运行相同的功能,我不知道为什么!
答案 0 :(得分:3)
您需要实际调用您的功能
if EnteredPass.isalpha():
而不是
if EnteredPass.isalpha:
后者只是隐式将函数对象转换为bool
,这将始终导致True