sydneymoss8412 sydneymoss8412
  • 07-04-2020
  • Computers and Technology
contestada

Write a function check_halves() that recursively processes the first half and second half of a string, counting how many letters the halves have in common, stopping when the first mismatch is found

Respuesta :

kendrich
kendrich kendrich
  • 12-04-2020

Answer:

The program code is at explaination

Explanation:

Below is the Python Function;

def check_halves(s):

# exact half not possible condition

if len(s)%2!=0:

return 0

halflen=len(s)//2

s1=s[:halflen]

s2=s[halflen:]

#null string condition

if len(s1)==0 or len(s2)==0:

return 0

#checking 1st digit of string recursively

if s1[0]==s2[0]:

return 1+check_halves(s1[1:]+s2[1:])

else:

return 0

You will find the input and output ad attachment.

Ver imagen kendrich
Answer Link

Otras preguntas

which best defines homeostasis
all whole numbers are also rational numbers?
What is the percent of 5/9
a. Discuss one situation when you would use wormbase first? b. Discuss one situation when you would use OMIM first? c. Discuss one situation when you would use
Mrs. Eaton's class is participating in the "Box Tops for Education" campaign. On the first day, her class collected 2 tops. On the third day, her class collecte
What is the decimal for 263/829449?
All of the following were factors in the failure of the United States to join the League of Nations after the First World War EXCEPT: (A) fear of further involv
What is an cell described in
how do you solve 7 1/5-6 2/5
Of the muscles listed, which is found in the upper body? A. pectorals B. glutes C. gastrocnemius