g The function below takes a single string parameter: sentence. Complete the function to return everything but the middle 10 characters of the string. You can assume that the parameter always has at least twelve characters and is always an even number of characters long. Hint: To find the middle of the string, you can half the length of the string (floor division). Then slice out 5 less than the middle to 5 more than the middle.

Respuesta :

Answer:

  1. def processString(sentence):
  2.    middle = len(sentence) // 2
  3.    output = sentence[0: middle - 5] + sentence[middle+5:]
  4.    return output
  5. print(processString("I have a dream"))

Explanation:

Create a function processString that take sentence as input paratemer (Line 1).

Next create a variable middle to hold the value of middle index of sentence string (Line 2)

Build the output string by slicing the input sentence from first character to character middle - 5th and from middle + 5th till the end of the string (Line 3).

Test the function using a sample sentence and we shall get the output "I am"

The function that takes a single string parameter and return everything but the middle 10 characters of the string is as follows:

def omitstring(string):

    center = len(string) // 2

    y = string[0: center - 5] + string[center + 5:]

    return y

print(omitstring("I am definitely a brainly fans"))

Code explanation:

The code is written in python.

  • We defined a function named "omitstring" and it has the parameter called "string".
  • The variable "center"  is used to divide the string into two.
  • Now we cut the middle 10 numbers from the string.
  • Then we return it.
  • Finally, we call the  function "omitstring" with the parameter.

learn more on python here: https://brainly.com/question/26967586

Ver imagen vintechnology

Otras preguntas