这是我的编码:
def main():
global x
PASSWORD_LOG_FILE = "ITWORKS_password_log.txt"
no_of_pw_small = 0
no_of_pw_big = 0
password_log_list = []
input_file = open(PASSWORD_LOG_FILE, "r")
for line in input_file:
password_log_list.append(line.strip("\n"))
for x in password_log_list:
print(x)
for line in password_log_list:
if "password < 6" in line:
no_of_pw_small = no_of_pw_small + 1
elif "password > 10" in line:
no_of_pw_big = no_of_pw_big + 1
print("The number of small password attempts is", no_of_pw_small)
print("The number of large password attempts is", no_of_pw_big)
input_file.close()
说您想要什么,我已经知道了。 现在,引用的文件有大约30行错误的密码尝试,其特征是过小或过大。此处的目标是计算文件中哪些元素的密码太小而密码太大,然后输出这两个元素的总数。我似乎无法做到。它在通过列表时输出整个方程,而不仅仅是整个方程。任何人都可以理解并解决似乎是我的困境吗?那太好了。谢谢。
答案 0 :(得分:0)
将这两行移出for循环:
print("The number of small password attempts is", no_of_pw_small)
print("The number of large password attempts is", no_of_pw_big)