There’s something wrong with this code for generating a password [on hold]

问题内容:

import random

def gen():

characters = 
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!123$4%5^6&7*8(9)0_-+='

length = input('What is the password length? It must be between 8 and 24 characters: ')
length = int(length)

if length < 8:
    print ('Your password must be 8 - 24 charcters long!')
    gen()

elif length > 24:
    print ('Your password must be 8 - 24 charcters long!')
    gen()

else:
    password = ''
    for c in range(length):
        password += random.choice(characters)
    print(password)

gen()

There’s something wrong with this code and i don’t know know what. The error that keeps showing up is as follows. ‘TypeError: gen() missing 1 required positional argument’. I don’t know why this keeps happening. If anyone can help then it would be greatly appreciated. I’m trying to make the code create a random string with the characters provided. The error is on line 24.

问题评论:

1  
indent your code properly please. And post the line number that raises the Error.
    
The title of your question should give some indication of your question’s content. Not just “something wrong”.

原文地址:

https://stackoverflow.com/questions/47755658/theres-something-wrong-with-this-code-for-generating-a-password

Tags:

添加评论