Respuesta :
Answer:
Following are the program in the Python Programming Language.
# define function.
def return_second_word(sentence):
#remove all the spaces from the sentence
sentence=' '.join(sentence.split())
#the list is split from spaces
my_list = sentence.split(" ")
#return the list
return my_list[1]
#define main function
def main():
#get input from the user
se = input("Enter the sentence: ")
#print and call the function
print(return_second_word(se))
#condition to execute the main function
if __name__ == "__main__":
#call main function
main()
Output:
Enter the sentence: I love python
love
Explanation:
Here, we define the function i.e., "return_second_word()" and pass an argument "sentence", inside the function.
- Remove all the spaces from the variable "sentence" and again store in the variable "sentence".
- Set the variable "my_list" that store the split value of the variable "sentence".
- Return the list and close the function.
Finally, we define the main function and inside the main function.
- Get input from the user in the variable "se"
- And pass the variable "se" in the argument list during the calling of the function "return_second_word()".
- Then, print and call the function "return_second_word()".
- Set the if statement to call the main function then, call the main function.
The function is an illustration of string manipulations.
String manipulation involves creating and editing of strings.
The function in Python, where comments are used to explain each line is as follows:
#This defines the function
def return_second_word(sentence):
#This removes all spaces in the sentence variable
sentence=' '.join(sentence.split())
#This splits the words in to a list
allWords = sentence.split(" ")
#This returns the second word
return allWords [1]
Read more about similar program at:
https://brainly.com/question/14282285