Answer:
In Python:
mystr = input("Sentence: ")
mylist = []
word = ""
for i in range(len(mystr)):
if not i == len(mystr)-1:
if not mystr[i] == " ":
word+=mystr[i]
else:
mylist.append(word)
word = ""
else:
word+=mystr[i]
mylist.append(word)
print(mylist)
Step-by-step explanation:
Prompt the user for an input sentence
mystr = input("Sentence: ")
Initialize an empty list
mylist = []
Initialize each word to an empty string
word = ""
Iterates through the input sentence
for i in range(len(mystr)):
If index is not the last, the following if condition is executed
if not i == len(mystr)-1:
If the current character is not space
if not mystr[i] == " ":
Append the character to word
word+=mystr[i]
If otherwise
else:
Append word to the list
mylist.append(word)
Set word to an empty string
word = ""
If otherwise; i.e. If index is not the last
else:
Append the last character to word
word+=mystr[i]
Append word to the list
mylist.append(word)
Print the list
print(mylist)