I am in a course and try to find my problem. I can't understand why if I enter something other than 9 digits, the if
should raise the StopIteration
and then I want it to go to except
and print it out. What is the problem?
def check_id_valid(id_number):if len(str(id_number)) != 9: raise StopIterationelse:lst_id = list(map(int,str(id_number)))lst_id[1::2] = map(lambda x: x * 2, lst_id[1::2])lst_id = map(lambda x: (x % 10 + x // 10), lst_id)num1 = sum(lst_id)if num1 % 10 == 0:return Trueelse:return Falsedef id_gen(id2):index = 0while index < 10:id2 += 1if check_id_valid(id2):index += 1yield id2def main():try:gen_idnum = id_gen(int(input("Enter id number : ")))for n in gen_idnum:print(n)except StopIteration as e:print(e)except ValueError as e:print(e)if __name__ == '__main__':main()