''' e-mail 1: e-mail 2: Purpose: experience the thrill of string manipulation ''' # get input s = input( 'Enter a line of text: ' ) ############################################################################ # determine n -- the length of s n = len( s ) # len() is a built-in function for determining the length of a sequence (e.g., string) # display result print( ) print( 'The input has length:', n ) ############################################################################ # determine last_index -- the index of the last character in s last_index = n - 1 # indices start at 0, so if a string has length n, the last character has index n-1 # determine last_character -- the last character in s last_character = s[ last_index ] # brackets allow us to peak into a screen # display result print( ) print( 'The last character ( i.e., at index', last_index, ') is:', last_character ) ############################################################################ # determine one_third_n -- the index of a character about 1/3 of the way through s one_third_n = n // 3 # determine two_thirds_n -- the index of a character about 2/3 of the way through s two_thirds_n = 2 * n // 3 # determine middle -- the middle third of s middle = s[ one_third_n : two_thirds_n ] # display result print( ) print( 'The middle of the input is:', middle )