Question
Python Hello I am trying to learn basic recursive function on Python and I am doing some of few exercises for practice. I am trying
Python
Hello I am trying to learn basic recursive function on Python and I am doing some of few exercises for practice. I am trying to make a function that returns the number that numbers in the list are strictly increasing using recursive, but counting algorithm is problem here is my code so far...
def count_increasing_number(string, number=0): #If string length is 1, ans is 1 counter = 1 for i in range(1, len(string)-1): #If first part is greater than previous number if int(string[:i]) > number: #If last part is empty, increment ans res_string = string[i:] if len(res_string) == 0: counter += 1 #Proceed with the remaining part else: number = int(string[:i]) counter += count_increasing_number(res_string, number) return counter
if __name__ == '__main__': print(count_increasing_number('19325')) print(count_increasing_number('10203')) I want to get 4 and 4 which are [1,9, 325], [1,9325], [19, 325], [19325] and [1, 02, 03], [1, 0203], [10, 203], [10203] but the output of my code are 6 and 5. There seems to be a problem with the counting algorithm, but I don't know where it's wrong. I know this is really stupid question, but I cannot find the solution. Please help me....
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started