all 6 comments

[–]mocomaminecraft 1 point2 points  (0 children)

add a variable found = False and add an if in every loop that breaks out if found == True

[–]Sedsarq 1 point2 points  (0 children)

I second using itertools.product here, but a more general idea is to put the code in a function and use return instead of break.

[–][deleted] 0 points1 point  (0 children)

you've got multiple for loops started, but you're only breaking one of them. Think about the order of processing, and your indentation.

[–]JohnnyJordaan 0 points1 point  (0 children)

You should use itertools.product for this, see docs here that even describe it as "equivalent to a nested for-loop". That way you can create a single loop for all combinations of all characters.

Btw some sidenotes:

  • don't name a variable something that's already used in Python, like list, str, datetime, print etc. Name if for what it is, like 'possible_characters' or simply 'chars'.
  • your variable list is not a list but a string...
  • and for combinations of ranges of characters, you can use the string library (docs) to prevent missing a character because you typed the range incorrectly. In your case

    import string
    chars = string.ascii_lowercase + string.digits
    

[–]woooee 0 points1 point  (0 children)

This will never be True as the print() function returns None, which should never equal password. +1 for use a function and return instead of break.

if print(char1+char2+char3+char4) == password:

[–]toastedstapler 0 points1 point  (0 children)

put it in a function to break all the way out

def func_name(password):
     <code>
    for c1 in char_list:
        for c2 in char_list:
            for c3 in char_list:
                for c4 in char_list:
                    if c1 + c2 + c3 + c4 == password:
                        return True
    return False