Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python. Write a function substring(string, ch) thatreturn the first substring from string that starts andend with a single character ch. The function shouldreturn None

In python. Write a function substring(string, ch) thatreturn the first substring from string that starts andend with a single character ch. The function shouldreturn None if it can’t find any substring that startsand ends with ch, or return the first substring if more thanone exists.

Note the following:

  • capital and a small case of the same letter should be treatedas two different characters.
  • the returned substring must at least be of length two

Function header: substring(string, ch)

Input: a string string anda single character ch.

Output: the first (left-most) substringthat starts and ends with thecharacter ch or None if no such substringexists.

Examples:

>>> string = "aaa#bb#zzzz#kkkkkkk#"

>>> ch= "#"

>>> substring(string, ch)

'#bb#'

>>> string = "fff@sss@aaa@ggg@"

>>> ch= "@"

>>> substring(string, ch)

'@sss@'

>>> string = "wwklmonw$%^&www"

>>> ch= "w"

>>> substring(string, ch)

'ww'

>>> string = "qaaa"

>>> ch= "7"

>>> substring(string, ch)

None

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

Managerial Accounting Tools for business decision making

Authors: Jerry J. Weygandt, Paul D. Kimmel, Donald E. Kieso

5th edition

470506954, 471345881, 978-0470506950, 9780471345886, 978-0470477144

Students also viewed these Programming questions

Question

2. Construct a simple financial planning model.

Answered: 1 week ago

Question

explain the underlying concepts of accounting;

Answered: 1 week ago