0

I am a self taught beginner programmer learning python as my first language. I want to be clear in that I am not looking for a straight "This is the answer, MUHAHAHAHA!!!", I am just in need of a little nudge to help me figure this out. Now, if it turns out that what I have done has no feasible way of working... Well, if you could just hit me with a brick it would be much appreciated.

I am working on a Kata from coding wars that I think needs a recursion to solve. Here is the problem quoted from the site: "Write a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit."

and here is the code that I have developed:

'''

from functools import lru_cache

@lru_cache(maxsize = 1000)
def new_list(num, num_2=0):
    new_num = [int(y) for y in str(num)]
    new_num2 = 1
    count = 0
    for numz in new_num:
        new_num2 *= numz
    if new_num2 <= 9:
        return count
    else:
        count += 1
        new_list(new_num2, count)

''' I think the problem is with the list comprehension, but I am not sure what to do about it. I have run through it with pdb and the recursion is picking up the new variable new_num2, but the program keeps returning "None" unless the input num is a single digit.

ablueblaze
  • 11
  • 2

0 Answers0