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

I usually leave at 11:00,but today i leave at 10 :30.is this sentence correct?
how did ernest rutherford discovery affect the model of the atom
the gcf of the numbers in the expression (32+16) is
PLEASE HELP!Using these lines from Act II, explain the relationship between Macbeth's words and the words of Duncan's sons. Macbeth Had I but died an hour befo
Which part of the respiratory system is composed of a single layer of epithelial tissues surrounded by a network of capillaries? alveoli trachea bronchiole
Alexis buys 13 apples and eats 5 how many are left
A joint held together by fibrocartilage would be classified as a __________ joint.
How far from an airport can an airplane fly and return in 8 hours, if it's outgoing speed is 160 km per hour and it's returning speed is 240 km per hour
How does distance affect the perceived size of objects?
Do you think more innocent people are found guilty in criminal cases or civil cases