lundi 12 décembre 2022

I'm trying to make a random name generator, but the output is off every time

The generator is supposed make 10 names and pull the names from the tuples first and last then randomly generate an index and assign it to either first or last then append/write each first + last name to the .txt file as well as put each name on a new line. It's supposed to also removed the names from the copied list to ensure there are no name duplicates.

def generateNames(firstName, lastName, file):
   
   
    for i in range (10):
        firstName = list(firstName)
        lastName = list(lastName)
        name = (random.choice(firstName) + " " + random.choice(lastName))
        print(name)        
    print("\t\tYour Generated Names:")    
    

Whenever the code generates the names it looks like this

Please enter a file name:
d

Hit Enter to Generate.

. x
x t
. t
t .
d .
d t
t t
x x
x x
t x
        Your Generated Names:


File has been created.

Rather than the full names.




Aucun commentaire:

Enregistrer un commentaire