I need to iterate through a long number to find the 13 consecutive digits with the greatest product. My code to do this looks like:
def largest_product(long_number, running_total, total): long_number = str(long_number) count = -1 for digit in long_number: count += 1 if len(long_number[count:count+13]) == 13: for digi in long_number[count:count+13]: running_total *= int(digi) if running_total > total: total = running_total print total
However this results in running total being set to 0 after the first total is calculated, in spite of giving it a value of 1 when calling it. Sorry about lack of indentation. I'm new to posting on the forums and unsure how to use tabs.