Python Forum
help with While method - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: help with While method (/thread-6641.html)



help with While method - brawdhampshire - Dec-01-2017

EXAMPLE AS FOLLOWS:

Program: print each word in a quote...
start = 0
space_index = quote.find(" ")
while space_index != -1:
# code to print word (index slice start:space_index)
#Output should look like below:
they
stumble
who
run
fast
.

# [ ] Print each word in the quote on a new line
quote = "they stumble who run fast"
# HOW CAN THIS BE DONE PLEASE HELP!!! USING THE .FIND METHOD


RE: help with While method - RickyWilson - Dec-01-2017

s = 'foo bar baz'
print('\n'.join(s.split()))
Outputs:
foo
bar
baz



RE: help with While method - brawdhampshire - Dec-01-2017

THE EXAMPLE IS CONFUSING, THATS JUST HOW THE PRACTICE TASK WAS WRITTEN... IT SAYS TO USE THE .FIND FUNCTION WITH A WHILE LOOP TO ITERATE THRU THE QUOTE AND PRINT EACH WORD IN THE STRING ON SEPARATE LINES, I DONT KNOW HOW THIS IS DONE, I AM A BEGINNER AND WANT TO KNOW IF THERE IS MORE THAN ONE WAY TO DO THIS... THANKS

(Dec-01-2017, 06:41 PM)RickyWilson Wrote:
s = 'foo bar baz'
print('\n'.join(s.split()))
Outputs:
foo
bar
baz



RE: help with While method - micseydel - Dec-01-2017

@brawdhampshire, all-caps is often perceived as shouting and rude, please use less "loud" casing.

As for your problem, please show us your attempt in code tags (which will preserve indentation). A post like yours has a hard time attracting quality responses, since we aren't sure how much Python you know or how far into the task you are. If you show your best attempt, and can article any questions / concerns about it, then people can address something specific to your needs.


RE: help with While method - brawdhampshire - Dec-02-2017

oops.. that was posted before he replied, stating that the example i gave was confusing... i didnt know how to delete and reply, I apologize for it seeming to be a response to his as it was a response to mine... im new to forums and didnt know i cant delete a post after tem minutes...


RE: help with While method - micseydel - Jun-20-2018

FYI, I split https://python-forum.io/Thread-split-help-with-While-method out of this thread.