To start off, I just want to print the length of a hard coded string as follows:
#!/usr/bin/env python3
#NestedIfStuff.py
password = "dink"
print(str(password.len()))
But I get the error:
AttributeError: 'str' object has no attribute 'len'
What's wrong?
I need to convert user string input to a number. My statement on line 7 isn't working:
import itertools
import sys
alphaNum = 'abc'
password = 'cab'
guessLength = input("How many characters would you like to guess up to: ")
int(guessLength)
for x in range(0, guessLength+1):
guessList = [''.join(i) for i in itertools.product(alphaNum, repeat = x)]
for guess in guessList:
if (password == guess):
print("the password is " + password)
sys.exit()
print(guess)
Error:
Traceback (most recent call last):
File "E:/Python/Python36-32/SamsPrograms/FinalPasswordGuesser.py", line 10, in <module>
for x in range(0, guessLength+1):
TypeError: Can't convert 'int' object to str implicitly
What do I need to do?
You have forgotten to assign the integer in line 7:
guessLength = int(guessLength)