Is there any way to exclude lines from looping inside of a loop?

Solution for Is there any way to exclude lines from looping inside of a loop?
is Given Below:

I was writing this code for a password generator in python, but when i execute it, it displays “I generated some random Passwords, Pick the one you like!” each time with each password. Is there a way to exclude this line out of this loop? Please help! here is the code:

import random


chars = "[email protected]#$1234567890"

while 1:
    password_len  = int(input("Please specify the length of password:"))
    password_count =int(input("How many passwords should i generate?"))
    for x in range(0,password_count):
        password =""
        
        for x in range(0,password_len):
            password_char = random.choice(chars)
            password     = password + password_char
        print ("I generated some random Passwords, Pick the one you like!",password)

I want it to look like this:

Please specify the length of password:4.
How many passwords should i generate?2.
I generated some random Passwords, Pick the one you like!
[email protected]
hjh4

import random


chars = "[email protected]#$1234567890"

while 1:

    password_len  = int(input("Please specify the length of password:"))
    password_count =int(input("How many passwords should I generate?"))
    print ("I generated some random Passwords, Pick the one you like!")
    for x in range(0,password_count):
        password =""

        for x in range(0,password_len):
            password_char = random.choice(chars)
            password     = password + password_char
        print(password)

Your problem is that the print("I generated some random Passwords, Pick the one you like!") is put in the loop body which means it is executed with every loop.
To fix,move it outside the loop in front of/behind the for according to which you’d like better,just don’t forget to keep print(password) so you can see the passwords.

(I also fixed the slow string concats. BTW,you can save yourself some time typing—range(0,a) is the same as range(a))

import random


chars = "[email protected]#$1234567890"

while 1:

    password_len  = int(input("Please specify the length of password:"))
    password_count =int(input("How many passwords should I generate?"))
    print ("I generated some random Passwords, Pick the one you like!")
    for x in range(password_count):
        password = ''.join(random.choice(chars) for i in range(password_len))
        print(password)

Here is your code with few edits that you might want to consider to get the code output as you wanted-

import random


chars = "[email protected]#$1234567890"

password_len  = int(input("Please specify the length of password: "))
password_count =int(input("How many passwords should i generate? "))

print ("I generated some random Passwords, Pick the one you like!")

for x in range(0,password_count):
    password =""
    
    for x in range(0,password_len):
        password_char = random.choice(chars)
        password     = password + password_char
    print (password)

You might also want to change the range(0, password_count) and range(0, password_len) to simply range(password_count) and range(password_len) as it is implied that the range will begin with 0 (default value) if no other argument is provided.

You need to move print("I generated some random Passwords, Pick the one you like!") out of the first for loop and also, you can add print(password) at the end of the first for loop, so you can see all the passwords generated.

import random


chars = "[email protected]#$1234567890"

while 1:
    password_len  = int(input("Please specify the length of password:"))
    password_count =int(input("How many passwords should i generate?"))
    for x in range(0,password_count):
        password =""
        
        for x in range(0,password_len):
            password_char = random.choice(chars)
            password     = password + password_char
        print(password)
    print ("I generated some random Passwords, Pick the one you like!")