I want to generate a set of random characteres with a lenght determined with the value to pass via input()
import random
import string
a = [] # an empty array created
#length = int(input("Number of character in Password"))
length = input("Number of character in Password")
for _ in range(length):
a.append(random.choice(string.hexdigits))
b = ''.join(map(str, a)) # to remove gaps and joining elements of array a
print("The Generated Password is " + b)
#below error message
File "C:\Users\carlos\Desktop\folder_learn\file tttuntitled-7.py", line 6, in <module>
for _ in range(length):
builtins.TypeError: 'str' object cannot be interpreted as an integer
>Solution :
just use int() to convert what a string to an integer in Python
length = int(input("Number of character in Password"))