[Python] Why is My Python Script Ignoring the Break Statement [closed]

Discussão em 'Python' iniciado por Stack, Junho 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm writing a python program, but it doesn't work; I defined a function to accept a JSON file and password txt file that I've provided and then cross-check them for matching passwords in both documents before writing them to a new JSON file. This is not happening at all, in fact, there's something causing the the break to not execute so it does not go to the next lines. I have posted a snippet of my code below, is there a solution? I have already referred to this thread and after running the code again, it doesn't print any statements so my break is definitely being ignored.

    # Define function for loading a file's JSON data

    `def load_json(file_path):`
    `if not os.path.exists(file_path):`
    `print("Cannot open the file ", file_path)`
    `with open(json_file_path, 'rb') as file:`
    `data = json.load(file)`

    `user_wants_to_continue = True`
    `while user_wants_to_continue == True:`
    `json_file_path = input('Enter the full path of the file to exit (example: C:/test.txt) or [e] to exit: ')`
    `if json_file_path.lower() == "e":`
    `print("Goodbye!")`
    `user_wants_to_continue = False`

    Ask the user for password list file


    `passwords_file_path = input("Enter your password list file path: ")`

    Load usernames and hashed passwords from JSON file


    `user_data = load_json(json_file_path)`
    `if user_data is None:`
    `continue`

    Load password list


    `common_passwords = load_common_passwords(passwords_file_path)`
    `if common_passwords is None:`
    `break`

    Check if any passwords from password list match the user passwords


    `results = hash_password(user_data, common_passwords)`

    Save data in JSON file


    `script_dir = os.path.dirname(os.path.abspath(__file__))`
    `results_file_path = os.path.join(script_dir, 'password_check_results.json')`
    `with open(results_file_path, "w") as file:`
    `json.dump(results, file, indent=1)`
    `file.close`
    `user_wants_to_continue = False`

    Main function execution


    `if __name__ == "__main__":`
    `main()`

    Continue reading...

Compartilhe esta Página