Getting error "NameError: name 'letter' is not defined"

2.9k views Asked by At

I'm fairly new to python and don't know much but i tried to make a program that sees how fast it can guess a string in this case a password. I tried to create an individual variable for each letter by making a loop that sets the variable. (I added the print letter1... at the end so i can see if it works).Then when i went to test it i got this error.

letter[x] = password[x - 1:-(len(password)-1)]

NameError: name 'letter' is not defined

print "Password guesser"

password = raw_input('Enter Password (1-30 carechters only): ')
passwordLength= len(password)

for x in range(0,passwordLength):
    letter[x] = password[x - 1:-(len(password)-1)]

print letter1
print letter2
print letter3   
1

There are 1 answers

3
chickity china chinese chicken On BEST ANSWER

Since you're assigning letters with dictionary syntax, you may want to declare the letter variable as a dictionary: letter = {}, then output it as a dictionary. This may get you in the direction you want to go:

letter = {}

for x in range(passwordLength):
    letter[x] = password[x - 1:-(passwordLength-1)]

print letter[0]
print letter[1]
print letter[2]