Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Are there any statements that can be used to run the code(s) again?

import random
import sys


print("Password Generator")    
print("* Attention: - You may not generate a password with more than 70 characters\n"
      "             - You may not enter letters")

characters = "abcdefghijklmnopqrstuvwxyz" \
             "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*"
pass_length = input("Enter your password length: ")

Here I just want to make sure the information that the user’s input are numbers, not letters!

if pass_length.isnumeric() is False:
    sys.exit("Natural numbers only!")

Is there a statement that can automatically run the script again after the "if" statement above is activated?

 def password_gen_start():
        password = "".join(random.sample(characters, int(pass_length)))
        print("Your password has been generated: " + format(password))


if int(pass_length) >= 71 and pass_length.isnumeric() is True:
    sys.exit("Password cannot be longer than 70 characters!")

if int(pass_length) < 71 and pass_length.isnumeric() is True:
    password_gen_start()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You just have to put it in a while loop :

stop = ""
while stop != "yes":
    pass_length = input("Enter your password length: ")
    while not pass_length.isnumeric():
        pass_length = input("Natural numbers only !\n Enter your password length: ")
    # you put here the stuff that you want to execute
    stop=input("do you want to stop ?")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading