# 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, Fall 2024 # # 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 = input("Type your line (^D to quit): ") except EOFError as msg: print("Bye!! --", msg) break # break it into words and print them out ct = ct + getwords(line) print("Number of words in all the lines:", ct)