我正在设计一个系统,允许用户输入一个字符串,以及由非字母数字字符数量确定的字符串的强度。积分应如下授予:每个非阿尔纳姆字符+1,最多3个非阿尔纳姆字符。Python - 查找字符串中的所有非字母数字字符
def non_alnum_2(total,pwd):
count = 0
lid = 3
number = 0
if pwd[count].isalnum():
if True:
print "Nope"
if False:
print "Good job"
count = count + 1
number += 1
if number > lid:
number = lid
return number
total = 0
number = 0
pwd = raw_input("What is your password? ")
non_alnum_2(total, pwd)
print total
total += number
我刚刚开始编码,所以我很抱歉,如果这看起来像一个非常初级的问题。
你可能要考虑*正则表达式*。 – fuesika
@pyStarter:'isalnum'的正则表达式让事情变得更加复杂无理。 – abarnert