我写的剧本如下:
numString = []
count = 0
while(True):
numInput=raw_input("Please enter your password\n")
count = count + 1
if numInput!="rusty":
numString.append(numInput)
else:
break
def write_textfile(filename):
ofile = open('wrongpasswords.txt','w')
ofile.write("\nIncorrect password 1:" + numString[0])
ofile.write("\nIncorrect password 2:" + numString[1])
ofile.write("\nIncorrect password 3:" + numString[2])
ofile.write("\nCorrect password entered on " + str(count)+"th entry")
ofile = open('wrongpasswords.txt', 'r')
for line in ofile:
print line
ofile.close()
ofile = open('wrongpasswords.txt', 'r')
write_textfile(ofile)
打印以下内容
Incorrect password 1: rusty123
Incorrect password 2: Rusty
Incorrect password 3: rustless
Correct password entered on 4th entry.
我想写一个可以打印以下内容:
Incorrect password 1: rusty123 , wrong by 3 characters.
Incorrect password 2: Rusty , wrong by 1 characters.
Incorrect password 3: rustless , wrong by 4 characters.
Correct password entered on 4th entry.
我试过使用difflib
。你知道吗
你需要的是Hamming distance。你知道吗
在代码中这样使用它:
相关问题 更多 >
编程相关推荐