【发布时间】:2017-05-06 17:56:18
【问题描述】:
我的代码是
from random import *
guess = ""
password = input("Password: ")
letters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
while (guess != password):
for letter in password:
guessletter = letters[randint(0, 25)]
guess = str(guessletter) + str(guess)
print(guess)
print("Password guessed!")
input("")
我的目标是让它随机生成字母并将它们粘在一起以形成密码的长度,并这样做直到找到密码。每次我运行它时,它只会让命令提示符看起来像来自 Matrix 的东西。是不是我做错了什么?
附:我这样做是为了看看破解密码有多难。我无意侵入其他人的帐户。
【问题讨论】:
-
您正在打印所有猜测,因为
print(guess)在while循环中。如果您不想这样做,请不要打印所有猜测。 -
但是所有的猜测都不是密码的长度,它永远也猜不出来密码,哪怕只有3个字母。
-
我想你想在每个 while 循环开始时将你的猜测重置为空字符串
-
您在哪里将
guess重置为空字符串? -
@Code-Apprentice xD 感谢您的回复。我不得不说,在过去的 4 年里,我在调试方面进步了很多
标签: python for-loop while-loop