#random password generator
import random
unified_code = "awertyuiosqpdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890!@#$%^&*()_+"
passlength1=input("how long should your password be")
pass_length2=input("how long should your password be")
def generatrandompaassword():
length = random.randint(passlength1,pass_length2 )
password = ""
for index in range(length):
randomCharacter = random.choice(unified_code)
password = password + randomCharacter
return password
passworder = generatrandompaassword()
print(passworder)
print("This is your new password")
this won't let me post for some reason what is a comment
this is the code iv made I started python a couple of days ago so I'm pretty new to it
fist I tried putting one-variable and than asking the user for the input and inserting the input into the program and using that to find the length of how long the password should be can get help with this?
Code - Your code needed minor changes
# random password generator
import random
unified_code = "awertyuiosqpdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890!@#$%^&*()_+"
pass_length1 = int(input("What should be the min length your password be: "))
pass_length2 = int(input("What should be the max length your password be: "))
def generatrandompaassword():
length = random.randint(pass_length1, pass_length2 )
password = ""
for index in range(length):
randomCharacter = random.choice(unified_code)
password = password + randomCharacter
return password
passworder = generatrandompaassword()
print(passworder)
print("This is your new password")
The input your receive from the user is of type str
, so you need to convert it into int
data type.
Output
What should be the min length your password be: 5
What should be the max length your password be: 15
vyA7ROviA
This is your new password
Suggestions:
_
or camelCasing. pass_length1
and randomCharacter
are of two styles.generate_random_password
than generatrandompaassword
=
before and after.Read a bit about python PEP standards to make your code more readable.