0

Write a python function, find_ten_substring(num_str) which accepts a string and returns the list of 10-sub strings of that string.

A 10-sub string of a number is a sub string of its digits that sum up to 10. sample input='3523014' actual output=['5230', '23014', '523', '352']

i have tried the below code it is printing only one sub string that adds up 10 (only [28])and then terminating.

def find_ten_substring(num_str):
    sumi=0
    list1=[]
    substr=''
    for i in range(0,len(num_str)):
        for j in range(i,len(num_str)):
            sumi=sumi+int(num_str[j])
            substr=substr+num_str[j]
            if(sumi==10):
                list1.append(substr)
                print(list1)
                break
        sumi=0
        substr=''
        continue

num_str="2825302"
print("The number is:",num_str)
result_list=find_ten_substring(num_str)
print(result_list)
ganesh chandra
  • 29
  • 3
  • 11

1 Answers1

1

You specifically told it to quit as soon as it found that one solution. Look at the bottom of your outer loop:

sumi=0
substr=''
break

This resets the accumulation variables, but then breaks the loop rather than repeating. Remove the break and return to your code development -- you have other errors, starting with lack of any return value.

Also, you should learn basic debugging. For starters, a few print statements inside your code can trace the data and control flow. See this lovely debug blog for help.

Prune
  • 76,765
  • 14
  • 60
  • 81