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" . (python)my answer wassecondWord = sentence.substr(sentence.find(" ") + 1)secondWord = secondWord.substr(0, secondWord.find(" "))but i am keep on getting error message saying ⇒ You almost certainly should be using: [ ] ⇒ We think you might want to consider using: : ⇒ Solutions with your approach don't usually use: , (comma)

Respuesta :

Answer:

When you are working with substrings in python you should treat the strings as lists, according to your answer the corrected code is given below:

sentence = "This is a possible value of sentence."

secondWord = sentence[sentence.find(" ")+1:]

secondWord = secondWord[0:secondWord.find(" ")]

print(secondWord)

Explanation:

#Define the value of the sentence for testing

sentence = "This is a possible value of sentence."

#Define a variable temp that starts when a blank space is find in the sentence to the end, sentence[n:] --> means everything in string after index "n"

temp = sentence[sentence.find(" ")+1:]

#Define the secondWord variable, you start at index 0 because in temp we already delete the first word and ends when finds the other blank space.

secondWord = temp[0:temp.find(" ")]

print(secondWord)

ACCESS MORE