After coding this, I was wondering if there are any ways in which I can improve upon it. It generates a random string of characters and symbols the same length as what is entered by the user. It uses a separate list for each char list but I am sure it is using a very long-winded method!import random, sysletters = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]lettersnum = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9]letterssym = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,#,*, , $, +, -, .]lettersnumsym = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9,#, *, , $, +, -, .]def generator(length, num, sym, caps):    count = 0    password =     try:        test = int(length)    except ValueError:        error(LENGTH NOT VALID NUMBER)    if num.lower() == yes and sym.lower() == yes:        merge = lettersnumsym    elif num.lower() == yes:        merge = lettersnum    elif sym.lower() == yes:        merge = letterssym    while count <= int(length):        password = password + merge[random.randint(0, len(merge) - 1)]        count = count + 1    if caps.lower() == uppercase:        password = password.upper()    elif caps.lower() == lowercase:        password = password.lower()    print(PASSWORD:,password)def error(error):    print(error)    sys.exit(0)running = Truewhile running == True:    length = input(How long do you want the password?)    numbers = input(Do You Want It to Include Numbers?)    symbols = input(Do You Want It To Include Symbols?)    capital = input(Do You Want It To be uppercase or lowercase??)    generator(length, numbers, symbols, capital)    restart = input(Do You Want Restart?)    restart = restart.lower()    if restart in (yes, y, ok, sure, ):        print(Restarting\n----------------------------------)    else:        print(closing Down)        running = False
Generating a random string of characters and symbols
python;optimization;python 3.x;random