Dec-12-2020, 11:18 PM
(This post was last modified: Dec-13-2020, 01:16 AM by snippsat.
Edit Reason: Added code tag
)
Hi
I am trying to learn python and I am working with some problems in the book, I am trying to construct a function that reads the lines of a string input and prints out the words. I wish to remove the spacebars with a while loop. Here is the code for simply displaying the string:
-----------------------------------------------------------------------
And here is my attempt in trying to remove the spacebars with a while loop.
Why doesn't my whileloop work? How do i change it so i don't have the spacebars in the final outprint?
I am trying to learn python and I am working with some problems in the book, I am trying to construct a function that reads the lines of a string input and prints out the words. I wish to remove the spacebars with a while loop. Here is the code for simply displaying the string:
1 2 3 4 5 6 7 8 9 10 |
def tokenize(lines): for line in lines: start = 0 while start < len (line): print (line[start]) start = start + 1 tokenize([ 'apple pie' ]) |
And here is my attempt in trying to remove the spacebars with a while loop.
1 2 3 4 5 6 7 8 9 10 11 |
def tokenize(lines): for line in lines: start = 0 while start < len (line): while line.isspace = = False : print (line[start]) start = start + 1 tokenize([ 'apple pie' ]) |