# Words.py Copyright (c) 2006 Kari Laitinen # http://www.naturalprogramming.com # 2006-05-27 File created. # 2006-05-27 Last modification. # The corresponding Java/C++/C# programs use special # keyboard input mechanisms. This program, however, uses # the standard raw_input() function. Indexing is # used to access the individual characters of the # given sentence. # The print statement automatically prints a space # character after each printing operation. # Python programs have the same kind of block structure # as programs written with other programming languages. # No braces { } are needed to specify where a block # starts or were it ends. Instead, indentation of program # statements are used to identify program blocks. # Statements beginning in the same column belong to the # same program block. print "\n This program separates the words of a" \ "\n sentence and prints them in wide form." \ "\n Type in a sentence.\n\n ", given_sentence = raw_input() character_index = 0 print "\n ", while character_index < len( given_sentence ) : character_in_sentence = given_sentence[ character_index ] if character_in_sentence == ' ' : print "\n ", else : print character_in_sentence, character_index += 1