简体   繁体   中英

While function into other while doesn't work

I'm trying to make a simple program using python that code some text into numbers, I got that part right but my second while just work the first time.

Can you help me understand why?

I put some prints so you can see whats going on.

tabela = ['89', '56', '48', '66', '99', '87', '79', '72', '26', "jj", '36', '57', '12', '10', '72', '15', "qq", '88', '47', '73', '92', '23', "ww", "xx", '39', '30', " "]
abc = ['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'," "]
i = 0
i2 = 0
resultado = ''

print("Escreva a sua frase", end=" ")
texto = input()

while i<len(texto):
    print (i, "menor", len(texto))
    while i2<len(tabela):
        print (i2, "menor", len(tabela))

        print(abc[i2], texto[i])
    if abc[i2] == texto[i]:

        resultado = resultado + tabela[i]          
        print (resultado)
    i2 += 1

i += 1

我必须将i2 = 0放在第一个 while 下,以便它重置i2直到第一个循环结束

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM