Please read documentation,
random
has a usage warning at the top of the documentation:Warning: The pseudo-random generators of this module should not be used for security purposes. Use
os.urandom()
orSystemRandom
if you require a cryptographically secure pseudo-random number generator.Use string formatting, this simplifys the creation of strings.
Have a standard for your indentation. I'm honestly surprised this code runs with your tabbing.
You can simplify your equality checks, rather than doing
a == b or a == c
, you can usea in {b, c}
. I use a set due to the peephole optimization.Use loops, if you use
for _ in range(amount)
you can reduce your code significantly.Move duplicate code into one function, in this case move your prints of the password out of;
small
,med
, andbig
. And put it ingenerate
.Make a single function to be able to make any sized input.
Change
generate
to account for this.Use a
main
. You want to keep things out of global scope, so it's as small as possible. This can lead to performance improvements This can lead to performance improvements.Protect your main function with a
if __name__ == '__main__':
guardif __name__ == '__main__':
guard.You can simplify the for loop to a list comprehension, this documentation may be easier to understand this documentation may be easier to understand.
You can define your letters as a global constant, so that if you do need them again later, you can use the one we've defined. And so if at a later date you want to add or remove letters, then you can without having to change multiple strings.
Please read documentation,
random
has a usage warning at the top of the documentation:Warning: The pseudo-random generators of this module should not be used for security purposes. Use
os.urandom()
orSystemRandom
if you require a cryptographically secure pseudo-random number generator.Use string formatting, this simplifys the creation of strings.
Have a standard for your indentation. I'm honestly surprised this code runs with your tabbing.
You can simplify your equality checks, rather than doing
a == b or a == c
, you can usea in {b, c}
. I use a set due to the peephole optimization.Use loops, if you use
for _ in range(amount)
you can reduce your code significantly.Move duplicate code into one function, in this case move your prints of the password out of;
small
,med
, andbig
. And put it ingenerate
.Make a single function to be able to make any sized input.
Change
generate
to account for this.Use a
main
. You want to keep things out of global scope, so it's as small as possible. This can lead to performance improvements.Protect your main function with a
if __name__ == '__main__':
guard.You can simplify the for loop to a list comprehension, this documentation may be easier to understand.
You can define your letters as a global constant, so that if you do need them again later, you can use the one we've defined. And so if at a later date you want to add or remove letters, then you can without having to change multiple strings.
Please read documentation,
random
has a usage warning at the top of the documentation:Warning: The pseudo-random generators of this module should not be used for security purposes. Use
os.urandom()
orSystemRandom
if you require a cryptographically secure pseudo-random number generator.Use string formatting, this simplifys the creation of strings.
Have a standard for your indentation. I'm honestly surprised this code runs with your tabbing.
You can simplify your equality checks, rather than doing
a == b or a == c
, you can usea in {b, c}
. I use a set due to the peephole optimization.Use loops, if you use
for _ in range(amount)
you can reduce your code significantly.Move duplicate code into one function, in this case move your prints of the password out of;
small
,med
, andbig
. And put it ingenerate
.Make a single function to be able to make any sized input.
Change
generate
to account for this.Use a
main
. You want to keep things out of global scope, so it's as small as possible. This can lead to performance improvements.Protect your main function with a
if __name__ == '__main__':
guard.You can simplify the for loop to a list comprehension, this documentation may be easier to understand.
You can define your letters as a global constant, so that if you do need them again later, you can use the one we've defined. And so if at a later date you want to add or remove letters, then you can without having to change multiple strings.
Please read documentation,
random
has a usage warning at the top of the documentation:Warning: The pseudo-random generators of this module should not be used for security purposes. Use
os.urandom()
orSystemRandom
if you require a cryptographically secure pseudo-random number generator.Use string formatting, this simplifys the creation of strings.
Have a standard for your indentation. I'm honestly surprised this code runs with your tabbing.
You can simplify your equality checks, rather than doing
a == b or a == c
, you can usea in {b, c}
. I use a set due to the peephole optimization.Use loops, if you use
for _ in range(amount)
you can reduce your code significantly.Move duplicate code into one function, in this case move your prints of the password out of;
small
,med
, andbig
. And put it ingenerate
.Make a single function to be able to make any sized input.
Change
generate
to account for this.Use a
main
. You want to keep things out of global scope, so it's as small as possible. This can lead to performance improvements.Protect your main function with a
if __name__ == '__main__':
guard.You can simplify the for loop to a list comprehension, this documentation may be easier to understand.
You can define your letters as a global constant, so that if you do need them again later, you can use the one we've defined. And so if at a later date you want to add or remove letters, then you can without having to change multiple strings.
import random
r = random.SystemRandom()
r.choice()
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz"
def choice_over(letters, amount):
choice = r.choice
return ''.join(choice(letters) for _ in range(amount))
def generate():
print("How big do you want your password?")
while True:
try:
choice = int(input("please input the length >> "))
break
except ValueError:
print('Please enter a number.')
generatepassword = choice_over(LETTERS, choice)
print(generatepassword)
print("The passwords consists of: {} Characters".format(len(generatepassword)))
print("\n")
def main():
again = 'yes'
while again in {'yes', 'y'}:
generate()
print("\n")
print("Do you want to generate another password? [yes] or [no] >> ")
again = input()
if __name__ == '__main__':
main()