Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I get the len of nontype

Hello guys I’m trying to write a program that generate a random password then cracks is it but I’m getting the error object of type ‘NoneType’ has no len()

from random import choice
from string import ascii_lowercase 

def nrndprint(n):
  k=(''.join(choice(ascii_lowercase) for i in range(n)))  #.join
  print(k)
nrndprint(6)
import itertools
def crack_pass(argpass):
  alplist = list(map(chr,list(range(ord('a'),ord('z')+1))))
  for combi in itertools.product(alplist,repeat=len(argpass)):
    if "".join(combi)==argpass:
      return combi
  return '-1'
passwd = nrndprint(4)
print(passwd)
print(crack_pass(passwd))

I’m getting:

#mqjz
#None

Expected:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#mqjz
#('m','q','j','z')

>Solution :

You can’t calculate the length of NoneType.

Your function nrndprint() doesn’t return anything. Adding return k will solve your problem.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading