New to python and working on and on daily studying a word generator. I'm testing restrictions IE set word length, making sure it has at least 1 upper, lowercase and digit in it etc.
import random
from string import ascii_uppercase, ascii_lowercase, ascii_letters, digits
pool = ascii_letters + digits
wordLen=random.randint(7,14)
answer = random.sample(pool, wordLen)
while True:
if not any(char.isupper() for char in answer):
answer[random.randrange(len(answer))] = random.choice(ascii_uppercase)
continue
if not any(char.islower() for char in answer):
answer[random.randrange(len(answer))] = random.choice(ascii_lowercase)
continue
if not any(char.isdigit() for char in answer):
answer[random.randrange(len(answer))] = random.choice(digits)
continue
break
answer = ''.join(answer)
I'd like to add a further restriction -- making sure consecutive chars aren't the same. Now I've studied string manipulation but simply can't find out how I can apply it. Let me show you something I've studied about string comparison
if stringx == stringy:
print 'they are the same'
else
print 'they are different'
I get the actual comparison part but I don't get how I can make the statements run again to generate another character again, disregarding the one it's just made. Any suggestions would be appreciated
stringx == stringxThat's always going to be true. You're comparing it to itself.