Search code examples
pythonpython-3.xrandomgenerator

Random Key Generator In Python 3


I've made a random key generator, That can even be used for creating a new password for you.

import random
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
while 1:
    key_len = int(input("What length would you like your key to be?: "))
    key_count = int(input("How many keys would you like?: "))
    for x in range(0,key_count):
        key = ""
        for x in range(0,key_len):
            key_char = random.choice(chars)
            key = key + key_char
        print("Here's your key: ",key)

Output:

What length would you like your key to be?: 4
How many keys would you like?: 1
Here's your key: 1337
What length would you like your key to be?: 

Solution

  • for x in range(0,key_len)
    

    you forgot to put colon to end. After I put colon code worked for me

    for x in range(0,key_len):