In [4]:
import random # This will put a random set of numbers in the password later
import string # This will make the passwords n' stuff strings
        
def generate_password(lengthOfPassword): # Defining new_Password...
    myCharacters = string.ascii_letters + string.digits + "!@#$%^&*()<>?{}" # This will collect variables and numbers to create a random password
    myPassword = " ".join(random.choice(myCharacters) for i in range(lengthOfPassword)) # Determines the length of password
    return myPassword # Returning the password to me
    
def menu(): # Defining menu...
        print("Main Menu") # Telling that this is the main menu
        print("1. View Passwords") # See your previous passwords
        print("2 Create New Password") # Create a new password
        print("3 Exit") # Exit the program
        
        choice = input("Enter what you want to do ==>") #Telling us to make a choice
        if choice == '1': # If you chose 1...
            with open("my_passwords.txt", 'r') as f: # Opening the txt file
                print(f.read()) # Allowing you to read the file
        elif choice == '2': # If you chose 2...
            myProgram = input("Enter the program you would like to use the password for? ==>") # What program the password is going to
            lengthOfPassword = int(input("How many digits do you want the password to be? ==>")) # How many digits the password is
            myPassword = generate_password(lengthOfPassword) # Generating the randomizer
            print(f"The password for {myProgram} is {myPassword}") # The endoong result
            with open("my_passwords.txt", '+a') as f: # Opening the txt file
                  f.write(f"{myProgram}: {myPassword}: \n") # Telling what is in the txt file
        elif choice == '3': # If you chose 3...
            print("Thank you for using the password generator! See you later! :)") # Nice ending message and ending the program
         
            
        else: # If you chose ANYTHING else...
            print("Error. Please Try Again") # Error pops up and you restart the program
                          
#if __name__ == '__Main__':
menu() # You go back to the main menu
Main Menu
1. View Passwords
2 Create New Password
3 Exit
Enter what you want to do ==>2
Enter the program you would like to use the password for? ==>a
How many digits do you want the password to be? ==>10
The password for a is c I P % b J t w D f
In [ ]:
 
In [ ]:
 
In [ ]: