''' Purpose: get an input code phrase and list of indices. Determine the hidden message by using the indices to peek into the code phrase ''' # get the code phrase that contains hidden message reply = input( "Enter code phrase: " ) print() # clean up reply to get code phrase with no leading or trailing blank space code_phrase = reply.strip() # print the code phrase print( "Code phrase:", code_phrase ) print() # get the list of indices (as string) for peeking into code phrase reply = input( "Enter indices for looking into code phrase: " ) print() # convert reply into a list of numeric strings numeric_strings = reply.split() # split() makes a NEW list out of a string. numeric_strings is a list and reply is still a string # build one-by-one the list of indices out of the numeric strings indices = [] for each in numeric_strings : # each is our loop variable, python automatically assigns it the next value in the list each run nbr = int( each ) indices.append( nbr ) # print the list of indices print( "Indices:", indices ) print() # build secret message (string) by peeking into code phrase using the # indices one-by-one message = "" # the infamous empty string will begin string accumulators for i in indices : # i is the classic loop variable, followed by j # i will represent the index that we're looking at each run of this for loop ch = code_phrase[ i ] # we want to grab one character out of our code phrase using an index message = message + ch # this will add on the new character to the message string we're building # strings vs. list: # strings: str = str + new_stuff # list: lst.append( new_stuff ) # LOOK AT WHAT IS BEING ASKED FOR. WE WILL ASK FOR A STRING OR A LIST AND THEY ARE NOT THE SAME # we are never going to trick you. we will be clear with what we want, just read the directionS print( "current index:", i ) print( "current character we're peeking at ( code_phrase[ i ] ):", ch ) print( "current message:", message ) print() # print secret message print( "Secret message:", message ) # problem solving: work through what you have, what you need, and then figure out how to get there # follow recommended algorithms when you get stuck problem solving, attend OH, and know that partial credit # will always be better than a zero