gpt4 book ai didi

python - 字符串索引超出范围错误Python for循环

转载 作者:行者123 更新时间:2023-12-03 08:50:52 26 4
gpt4 key购买 nike

我的简单暴力密码程序到目前为止可以正常运行,但是无论何时运行,它始终会打印出最后一个,并且出现字符串索引超出范围的错误。一切正常,我得到了想要的输出,但是无论何时while循环关闭并且程序停止运行,我仍然会收到错误消息。

userpassword = raw_input("Enter a password: ")

k = 0
cyclenumb = 0
newpasswordlist=[]

lowercaselist=["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"]
uppercaselist=["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"]
numberslist=["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
symbolslist=["~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "{", "[", "]", "}", "|", "\ ", ";", ":", "'", '"', ",", "<", ".", ">", "/", "?", " "]

while cyclenumb <= 10000:

for x in userpassword[k]:
for z in lowercaselist:
if x in z:
newpasswordlist.append(z)
k +=1
print newpasswordlist
if x is not z:
for x in userpassword[k]:
for z in uppercaselist:
if x in z:
newpasswordlist.append(z)
k +=1
print newpasswordlist
if x is not z:
for x in userpassword[k]:
for z in numberslist:
if x in z:
newpasswordlist.append(z)
k +=1
print newpasswordlist
if x is not z:
for x in userpassword[k]:
for z in symbolslist:
if x in z:
newpasswordlist.append(z)
k +=1
print newpasswordlist

if userpassword == newpasswordlist:
break

print newpasswordlist
print "Here is your original password " + userpassword

请帮助我解决这个简单的错误。

最佳答案

此代码中没有任何东西甚至试图检测k大于或等于userpassword的长度。例如,您可以在k增加时进行检查;如果太大,请退出while循环。

关于python - 字符串索引超出范围错误Python for循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41106039/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com