A 10-substring of a number is a substring of its digits that sum up to 10. For example, the 10-substrings of the number 3523014 are: 3523014, 3523014, 3523014, 3523014

A 10-substring of a number is a substring of its digits that sum up to 10.

For example, the 10-substrings of the number 3523014 are:
3523014, 3523014, 3523014, 3523014

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

Handle the possible errors in the code written inside the function.


5 comments:

  1. i'm trying to solve the same problem but couldnt understand the logic in the code.

    ReplyDelete
    Replies
    1. Use the following code instead.
      Here, "-" shows the identation spaces.


      def find_ten_substring(num_str):
      -result_list=[]
      --for i in range(0,len(num_str)):
      ---sum=0
      ---num=""
      ---for j in range (i,len(num_str)):
      ----sum=sum+int(num_str[j])
      ----if sum<10:
      -----num=num+num_str[j]
      ----elif sum==10:
      -----num=num+num_str[j]
      -----result_list.append(num)
      ----else:
      -----break
      --return result_list

      num_str="2825302"
      print("The number is:",num_str)
      result_list=find_ten_substring(num_str)
      print(result_list)

      Delete
  2. Great content material and great layout. Your website deserves all of the positive feedback it’s been getting. 상품권 현금화

    ReplyDelete

  3. def find_ten_substring(num_str):
    flag=0
    sum=0
    list=[]
    item=""
    tuple=()
    for i in range(0,len(num_str)):
    sum=sum+int(num_str[i])
    item+=num_str[i]
    if sum==10:
    flag+=1
    #print(flag,"flag")
    list.append(item)
    print(list)
    return find_ten_substring(num_str[flag:])
    break
    else:
    continue
    num_str="2825302"
    print("The number is:",num_str)
    result_list=find_ten_substring(num_str)

    ReplyDelete
  4. //this can be a reduced code
    def find_ten_substring(s):
    L=[];sum=0;m=[]
    for i in range(0,len(s)):
    sum=0
    for j in range(i,len(s)):
    sum=sum+int(s[j])
    if(sum==10):
    L.append(s[i:j+1])
    if(sum>10):
    break
    return L
    num_str="3523014"
    print("The number is:",num_str)
    result_list=find_ten_substring(num_str)
    print(result_list)

    ReplyDelete

Write a python function, find_correct() which accepts a dictionary and returns a list as per the rules mentioned below. The input dictionary will contain correct spelling of a word as key and the spelling provided by a contestant as the value.

Write a python function,  find_correct()  which accepts a dictionary and returns a list as per the rules mentioned below. The input diction...