Characters repeating in String discovery [Python]

Asked

Viewed 208 times

0

The goal here is to discover the passwords, in trial and error even, and ta everything going well while the letters, but when they reach the numbers, they repeat themselves for a reason I really don’t understand. If anyone can find the error in the code, I am grateful.

import random
senha='TasLAVa4554'
alfa='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
num='123456789'
def breakK(x):
    ans=''
    for y in senha:        
        for z in alfa:
            if str(y)==str(z):
                print('Verificando aspectos...')
                ans+=str(z.upper())
            if str(y)==str(z.lower()):
                print('Verificando aspectos...')
                ans+=str(z.lower())
            else:
                print('Testando...')
                for n in num:
                    if str(y)==str(n):
                        print('Verificando aspectos')
                        ans+=str(n)
                    else:
                        print('Verificando aspectos')

    print(ans)
####
print(breakK(senha))    

1 answer

0


Note the loops. The first iterates over each character of the password, the second over each alpha character. In that you have an if with an Else and in that Else you iterate on one. This means that every time you enter Else, which repeats for each alpha character, you will test in one. The for n in num: should be on the same level as for z in alfa:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.