I am trying to break a sentence up into words and then print each word on a separate line. But I am not allowed to use the split function. It should be done using lists and such. So far I have:
text=input("Enter text:")+''
L=len(text)
i=0
while i!=L:
bi=i
while text[i]!='':
i=i+1
print(text[bi:i])
i=i+1
But this results in the sentence being broken up letter by letter:
i.e.
"Hello."
becomes:
H
He
Hel
Hell
Hello
Also, what I have now leaves off the last character. And I get the error message:
Traceback (most recent call last):
File "test.py", line 6, in <module>
while text[i]!='':
IndexError: string index out of range
What does this message mean?
while i < Lyou want the length -1 andwhile i < Lin the inner loop, you should use a for loop checking for whitespace