Reputation: 151
I have a script to generate random words,
import random
letters = ["a", "b", "c", "d","e", "f", "g", "h", "i", "j", "k", "l"]
def get_random_name(letters, length):
return ''.join(random.choice(letters) for i in range(length))
print(get_random_name(1,12))
But when I run, I am getting error :
TypeError: object of type 'int' has no len()
Please help. Where I am wrong ?
Upvotes: 0
Views: 741
Reputation: 180391
You are passing letters as an int, you need to pass the letters list:
print(get_random_name(letters,12))
Passing get_random_name(1,12)
you are trying to call random.choice(1)
which will obviously fail
Upvotes: 7