i writing code class , having trouble finding middle of line. have prompt user file, read it, split individual lines, , add specific word beginning, middle, , end of each line. not sure how middle
file = str(input("enter input file:" "")) my_file = open(file, "r") file_contents = my_file.read() #change "e"s "zw"s letter in file_contents: if letter == "e": file_contents = file_contents.replace(letter, "zw") #add "hokie" beginning, middle, , end of each line lines = file_contents.split('\n') #i know following line wrong, i'm not sure how fix middle_message = lines[len(lines) /2:] + "hokie" message = "hokie" + middle_message + "hokie"
you'll have better time solving of yourself.
here's hint though: should middle_message
contain? concrete example, if line 'abcd'
, want change line 'hokieabhokiecdhokie'
. see if can point out ab
, cd
parts come in code snippet.
Comments
Post a Comment