我似乎无法让这段代码添加函数中执行的所有点,然后在最后输出它。每次输入另一个密码时,它都返回值1。任何帮助都太好了!谢谢!!你知道吗
def length_pw():
points = int(0)
length = len(pword)
if length < 6:
print "%s is REJECTED"%pword
if length <=8:
points = points + 1
return points
else:
points = points + 0
print "%s is ACCEPTED"%pword
def upper_case():
points = int(0)
limit = 3
for each in pword:
if each.isupper():
points = points + 1
return points
else:
points = points + 0
def num_digits():
points = int(0)
limit= 3
for each in pword:
if each.isdigit():
points = points + 1
return points
else:
points = points + 0
def non_alpha_numeric():
points = int(0)
limit= 3
for each in pword:
if each.isalnum():
points = points + 1
return points
else:
points = points + 0
while True:
pword = raw_input("Enter Password: ")
points = 0
points = length_pw()
points = upper_case()
points = num_digits()
points = non_alpha_numeric()
print points
将每个函数的返回值依次赋给
points
值。您要做的是指定它的当前值和函数的返回值之和。这意味着Python(和大多数其他语言)为此操作提供了一些简化的语法:
您需要在每个函数调用之后添加点。例如
您遇到的根本问题是,函数没有正确地
return
点值。第一个并不总是返回任何东西(这与返回None
相同)。其他的都会在处理pword
的第一个字母后停止。你知道吗下面尝试解决这些问题,并清理或简化代码中的其他一些内容:
相关问题 更多 >
编程相关推荐