Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes And Databases On The Internet A Practical Guide To Functions And Applications

Authors: Paul Rangel

1st Edition

189848631X, 978-1898486312

Students also viewed these Databases questions