I Haz Codes

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Menu
Looping over a string

Copy the code below. This code will display all of the words in a string. Make the following changes.

  • Add two more words to the string.
  • change temp = temp + text[x] to temp = text[x] + temp. Run the code.
  • In the IF statement, store each word into a new string called “sentence”
  • Display the sentence at the end of the loop.
text = "hello world"
x = 0
temp = ""
while x < len(text):
    if text[x] == " ":
        print ("Found word ", temp)
        temp = ""
    else:
        temp = temp + text[x]
    x = x + 1


You need to log in or create an account to submit code!

Comments are closed.

Information