In [19]:
#This program generates random username and password

import random
import string

file = open("output.txt","w") #open a new file named outpu.txt for writing

file.write("Username : Password\n") #add a header to the file

for x in range(1,6):
    userRange = random.randint(6,20) #length of username
    #print (userRange)

    passRange = random.randint(8,20) #length of password
    #print (passRange)

    #generate a random username using letters and digits with a length of userRange
    randUser = ''.join([random.choice(string.ascii_letters + string.digits) for x in range(userRange)])
    #print (randUser)

    #generate a random password using letters and digits with a length of passRange
    randPass = ''.join([random.choice(string.ascii_letters + string.digits) for x in range(passRange)])
    #print (randPass)
    
    file.write(randUser + " : " + randPass + "\n") #write generated username and password to file in username : password format

file.close() #close file