''' Purpose: separately prompt for a string s and a list of integers numbers. The program displays the string formed by using numbers as indices into s. ''' # get the string of interest for examination s = input( "Enter a string: " ) # "computer" # get the numeric inputs reply = input( "Enter indices: " ) # "5 1 7" string_sequence = reply.split() # ["5","1","7"] reply.split() broke it # up into a list of smaller substrings! # accumulate from the numeric inputs a list of integer indices. indices = [] # Create a list of numbers for our indices (accumulator) for ns in string_sequence: i = int( ns ) # Convert each numeric string to a number indices.append( i ) # Add number versions of each number to list! print( indices )# Yay! We got our list of numbers for the indices # we wanted by converting the numeric strings in string_sequence to # a list of numbers of those same numeric strings but as integers # so that we can work with the numbers. # acccumulate output string by using the indices one-at-a-time to look into s output_string = "" # String accumulator to build up a string # of my characters at those indices of interest for i in indices: # [5,1,7] character = s[ i ] # This is getting the character at that index # THIS IS CALLED SUBSCRIPTING -> get me character at this number position! # s[ 5 ] in 'computer' is 't' print( character ) output_string = output_string + character # Build up final string print() print( output_string )