I am creating a simple password generator application using python, since I new about random module so I employed it’s sample() function with a sequence of characters and length. But it is showing me this EOF error as
Traceback (most recent call last):
File "./prog.py", line 2, in <module>
EOFError: EOF when reading a line
here is my code
from random import *
length=int(input("What should be the length of Password: "))
sequence='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&/|?<>*'
password=''
mylist=sample(sequence,length)
for i in mylist:
password+=str(i)
print(password)
then i have tried it using try and except logic
from random import sample
try:
# Prompt the user to specify the desired length of the password
length = int(input("What should be the length of the password: "))
if length <= 0:
print("Please enter a positive integer for the password length.")
else:
# Define the sequence of characters to choose from
sequence = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&/|?<>*'
# Generate the password
password = ''.join(sample(sequence, length))
# Display the generated password
print("Generated password:", password)
except ValueError:
print("Invalid input. Please enter a valid number.")
except EOFError:
print("Input error. Unable to read input.")
I was expecting that this might give me a random sequence of characters of specified length which can be used as password.
1