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.
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.
i'm trying to solve the same problem but couldnt understand the logic in the code.
ReplyDeleteUse the following code instead.
DeleteHere, "-" 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)
Great content material and great layout. Your website deserves all of the positive feedback it’s been getting. 상품권 현금화
ReplyDelete
ReplyDeletedef 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)
//this can be a reduced code
ReplyDeletedef 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)