The main issue with func is a simple bug: a new variable i gets incremented each iteration instead of k. But starting with the line fh1 = ... the remaining code is gibberish in terms of Mathematica syntax, undefined functions, and the like. It really is not close enough to viability to offer much at this point-- it needs to be gone over with an instructor or TA.