Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with While method
#1
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
Reply
#2
s = 'foo bar baz'
print('\n'.join(s.split()))
Outputs:
foo
bar
baz
Reply
#3
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
Reply
#4
@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.
Reply
#5
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...
Reply
#6
FYI, I split https://python-forum.io/Thread-split-hel...ile-method out of this thread.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020