Assume that sentence is a variable that has been associated with a string consisting of words separated by single space characters with a period at the end. for example: "this is a possible value of sentence." write the statements needed so that the variable secondword is associated with the second word of the value of sentence . so, if the value of sentence were "broccoli is delicious." your code would associate secondword with the value "is" .

Respuesta :

The right code is,

secondWord = sentence.substr (sentence.find ("`") + 1);

secondWord = secondWord.substr (0, secondWord.find ("`"));

Answer:

The solution code is written in Python.

  1. text  = "broccoli is delicious."
  2. wordList = text.split(" ")
  3. secondword = wordList [1]

Explanation:

Firstly, let us declare a variable text and assign it with a string (Line 1).

Next, we can use the split() method and use single space character " " as the delimiter to separate the words in the string by turning it into a word list (e.g. ["broccoli",  "is", "delicious."]) (Line 2)

We can use the index 1 to address the second word from the wordList and then associate it with variable secondword (Line 3).