''' Purpose: examine a list of words ''' # get text from user reply = input( 'Enter text: ' ) print() # split text into words # .split() separates based on where it sees whitespace. # It doesn't split on like "number of inputs" but rather # wherever it sees whitespace. It gets the things around the # whitespace and makes each thing separated by whitespace a list # element in our list of smaller substrings we created by # splitting it. words = reply.split() # 'hi im nadia'-> ['hi','im','nadia'] # let's see what we got print( 'Supplied text =', reply ) print( 'words =', words ) print() # analyze text # w is the loop variable. We remember from last class that # the loop variable changes value in each iteration of this loop. # w is the first word in the list, runs through the loop, then w # is the next word in the list, runs through the loop, etc. all the # way to the end of the words list. # It repeats the for loop body for EACH new value of the loop variable. # (the number of things in your sequence) # Remember our sequences include (loops break sequences down into # the smaller pieces of a larger sequence!): # and the loop variable takes on each smaller part of the larger # sequence. # String (characters) # Lists (elements) # Range of Numbers (i,j) - numbers i to j - 1 for w in words : # reply is a string and words is a list # get current word's length len_w = len( w ) # echo current word and it's length print( w, ":", len_w ) # For loop body is indented! All of these statements are repeated # for each new value of the loop variable. # Loop variables can be anything! # FOR LOOP FORMAT # for LV in sequence: # loop body (all statements that get executed each time # we run through the loop) # Also feel free to like ask me to scroll up if you wanna see anything:)