# File: lines.py # Program to print words in a line # NOTE: a "word" is any sequence of non-blank characters # (user enters line) # # Matt Bishop, MHI 289I, Winter 2018 # # Break line into words and print the words one per line # parameter: line, the line to be split up def getwords(line): # create a list of words listwords = line.split(" ") print "Number of words in this line: ", len(listwords) # print them out one per line for i in listwords: print i return len(listwords) # read a line, break it into words, and print the words # calls: function getwords # get line from user ct = 0 while True: try: line = raw_input("Type your line: ") except: break # break it into words and print them out ct = ct + getwords(line) print "Number of words in all the lines:", ct