def madlib(template) // loop through and find/remove all of the replacements replacements = {} ind = 0 while ind < len(template) // check if we have found a replacement to perform if template[ind] = "<" // get the name of the replacement and add it to the list // if we haven't already encountered it ind += 1 replace_name = "" while template[ind] != ">" replace_name += template[ind] ind += 1 end while if not replace_name in replacements replacements.append(replace_name) end if ind += 1 else ind += 1 end if end while // prompt the user for replacement values replacement_values = {} for phrase in replacements replacement_values.append(input("enter " + phrase + ": ")) end for println // make replacements and output the story ind = 0 while ind < len(template) // check if we have found a replacement to perform if template[ind] = "<" // get the name of the replacement ind += 1 replace_name = "" while template[ind] != ">" replace_name += template[ind] ind += 1 end while // output the replacement print replacement_values[replacements[replace_name]] ind += 1 else print template[ind] ind += 1 end if end while end madlib madlib(" went for a walk in the park. " + \ "found a . decided to take it home.")