Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please read before posting an answer I need to write in python using only recusrion: function that gets (s1,s2,s3) - checks if s3 is a

Please read before posting an answer

I need to write in python using only recusrion:

function that gets (s1,s2,s3) - checks if s3 is a good combination of s1 and s2

rules -

1) s3 must be the same length as s1 + s2

2) the order of the letters must be the same as s1 and s2 but not necessarily one after another

examples :

s1 = "abc", s2 = "def" , s3 can be "abcdef" , "adbecf" and such on

I worte a code that need to be fixed :

def check(s1,s2,s3): l1, l2, l3 = len(s1), len(s2),len(s3) if (l1 == l2 == l3 == 0): return True if (l1 == 0) and (s2 == s3 or s1 == s3): return True if (l3 != (l1 +l2)): #or (l3 == 0 and (l1 > 0 or l2 > 0)): return False if s1 and s1[0] == s3[0]: return True and organized_comp(s1[1:], s2, s3[1:]) if s2 and s2[0] == s3[0]: return True and organized_comp(s1, s2[1:], s3[1:])

It doesn't work on this example : s1 = " ABZ" , s2 = "ABAXZ" , s3 = "ABAXABZZ" it gives me False and it needs to be True

examples u can run:

s1 = "", s2 = ", s3 = "" --- True

s1 = "", s2 = "abc", s3 = "abc" -- True

s1 = "12189" , s2 = "129" , s3 = "12181299" --- False

note -

1) if you need to use another function it must be recursion only.

2) if you need to use built in functions you can only use - index , find , split , [ : ], s1

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

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

More Books

Students also viewed these Databases questions

Question

Explain exothermic and endothermic reactions with examples

Answered: 1 week ago

Question

2. Why has the conflict escalated?

Answered: 1 week ago

Question

1. How will you, as city manager, handle these requests?

Answered: 1 week ago