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:

#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.

Leave a Reply