Python中boolean的命名有什么规定?
What regulations are there when naming boolean in Python?
我写了一个程序来确定密码是否强(有 10 个以上的字母,1 个以上的大写字母和数字),如果不是,它会要求一个更强的密码。为此,我选择使用布尔值,但 IDLE 说语法不正确并突出显示我的布尔名称。名称有问题还是我应该更正其他内容/
def length(long):
while len(long) < 10:
print("Please make your password longer, up to at least 10 characters.")
print("Your password is only " + str(len(long)) + " characters long")
print("Welcome to this student interface")
username = input("Please enter a username")
password = input("Please enter a strong password")
length(password)
bool Capcheck = False
bool DigCheck = False
serrors = []
while CapCheck = False or CapCheck = False:
length(password)
if not any(x.isupper() for x in password):
serrors.append("Your password needs at least 1 capital.")
else:
CapCheck = True
break
if not any(x.islower() for x in password):
serrors.append("......... Why?")
if not any(x.isdigit() for x in password):
serrors.append("You need to have at least 1 digit")
else:
DigCheck = True
break
if serrors:
print(" ".join(serrors))
password = input("Please enter a stronger password")
你的语法错误:
bool Capcheck = False
应替换为
Capcheck: bool = False
我写了一个程序来确定密码是否强(有 10 个以上的字母,1 个以上的大写字母和数字),如果不是,它会要求一个更强的密码。为此,我选择使用布尔值,但 IDLE 说语法不正确并突出显示我的布尔名称。名称有问题还是我应该更正其他内容/
def length(long):
while len(long) < 10:
print("Please make your password longer, up to at least 10 characters.")
print("Your password is only " + str(len(long)) + " characters long")
print("Welcome to this student interface")
username = input("Please enter a username")
password = input("Please enter a strong password")
length(password)
bool Capcheck = False
bool DigCheck = False
serrors = []
while CapCheck = False or CapCheck = False:
length(password)
if not any(x.isupper() for x in password):
serrors.append("Your password needs at least 1 capital.")
else:
CapCheck = True
break
if not any(x.islower() for x in password):
serrors.append("......... Why?")
if not any(x.isdigit() for x in password):
serrors.append("You need to have at least 1 digit")
else:
DigCheck = True
break
if serrors:
print(" ".join(serrors))
password = input("Please enter a stronger password")
你的语法错误:
bool Capcheck = False
应替换为
Capcheck: bool = False