''' 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 reply = input( "Enter text: ") text = reply.strip() # get the numeric inputs reply = input( "Enter some integers: " ) # We want a list of the numbers from the string of numbers numeric_string_list = reply.split() # accumulate from the numeric inputs a list of integer indices. indices = [] # list accumulator we're adding our number indices to for s in numeric_string_list: # run through list of numbers (strings) i = int( s ) # Convert each string of a number into an actual integer indices.append( i ) # Add it to our integer list of indices # acccumulate output string by using the indices one-at-a-time to look into s secret_message = "" # Our accumulator is an empty string because our output is a string! for i in indices: ch = text[ i ] # Grab the character at index i out of the string text secret_message = secret_message + ch # We are adding these characters we get at i one by one to the string # THE STRING IS UPDATED EACH TIME WE RUN THROUGH THR FOR LOOP AND REASSIGNED THE NEW # UPDATED VALUE AND RETAINS ITS FINAL VALUE SINCE IT WAS ORIGINALLY INITIALIZED # OUTSIDE THE FOR LOOP AND UDPATED WITHIN :) print( secret_message ) # .append() is for lists.