Q:

Breaking 2 for loops in Python

I have made small script with Python that brute forces given word and when it finds the word, it should stop.
from itertools import product
rangeone = int(raw_input("Set range1: "))
rangetwo = int(raw_input("Set range2: "))

question = raw_input("Give password: ")

alphabets = 'abcdefghijklmnopqrstuvwxyz1234567890'

for random in range(rangeone, rangetwo):
    loops = product(alphabets, repeat=random)
    for y in loops:
        password = ''.join(y)
        if password == question:
            print "done"
            break

But, it doesn't break the loop. It keeps going

A:

Your code has two loops, and the break can only breaks the inner loop. You could define a variable (e.g. stop). Once the word is found, you set it to True, to stop the outer loop:
from itertools import product
rangeone = int(raw_input("Set range1: "))
rangetwo = int(raw_input("Set range2: "))

question = raw_input("Give password: ")

alphabets = 'abcdefghijklmnopqrstuvwxyz1234567890'

stop = False
for random in range(rangeone, rangetwo):
    loops = product(alphabets, repeat=random)
    for y in loops:
        password = ''.join(y)
        if password == question:
            print "done"
            stop = True
            break   # breaks the inner loop
    if stop: break  # breaks the outer loop

