<jupyter_start><jupyter_text>Persistent BuggerWrite 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.<jupyter_code>from functools import reduce

def persistence(n):
    
    """ 
    Calculates multiplicative persistance
    Input: a positive number
    Output: the number of times you must multiply the digits until you reach a single digit.
    
    Examples: persistence(39) => 3 - Because 3*9 = 27, 2*7 = 14, 1*4=4 and 4 has only one digit.
              persistence(999) => 4 - Because 9*9*9 = 729, 7*2*9 = 126, 1*2*6 = 12, and finally 1*2 = 2.
    """
    
    # turn n into string
    digits = str(n)
    
    counter = 0
    while len(digits) > 1:   
        # use reduce function to multiply each digit and repeat process until len(digits) == 1
        digits = str(reduce((lambda x, y: x * y), [int(x) for x in digits]))
        counter += 1
    
    return counter<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup