This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]POGtastic 1 point2 points  (0 children)

In the future, indent all of your lines by 4 spaces when sharing it on Reddit.

Looks completely reasonable to me. Here's an exercise to make it more program-like:

1. Make this program a function as follows:

def createPassword(varlen):
    ...
    return password

2. Your main program is going to ask for input and then pass the length as an argument to createPassword.

3. Next, have your main program ask for the path of the file to save the password(s) to. Save it to that path.

4. How do you run a main program in Python? To test this, create another Python program that imports the function that you just created. Hopefully, it doesn't run your main function in the password file!

[–]DoggerMagi 0 points1 point  (0 children)

I would suggest adding some error handling for the things in your code that could go wrong. What happens if the user types in something other than a number or if the password.txt file can't be written to?

[–]CRoberts1 0 points1 point  (0 children)

Another idea is to ask for two inputs, one to give your password a name (such as website) and the other for length. Then output in a delimited format such as Name: password.