Encoding/Decoding Txt File Using Python

I have to develop a function named “decode(message_file)” that can read an encoded message from a .txt file and return the decoded version as a string. I know how to use Python and wish to use this language for my problem. I used a similar code from another topic similar to mine and I keep getting a NameError ‘lines’ not defined and I don’t know why. Also I’m very new to coding, so I’m just trying to practice as much as I can; thanks for any help!

Instructions:

Text to use:
133 land
160 sun
88 too
213 huge
47 dont
1 such
156 noun
155 student
237 brown
298 complete
3 play
233 cook
278 yard
259 clock
137 would
211 plain
299 excite
264 fire
37 wish
81 cool
36 child
129 past
234 colony
151 oil
284 dog
270 back
254 money
241 kind
111 open
221 finger
63 touch
271 are
217 dad
58 am
187 modern
82 meant
93 ocean
231 pitch
91 suit
245 town
122 east
89 over
135 group
84 good
8 kind
165 down
207 band
78 especially
20 organ
267 of
125 fire
130 out
226 area
87 touch
50 happen
96 sat
9 electric
208 wrote
225 buy
292 lot
149 stop
194 corn
120 where
18 check
274 live
59 best
272 hold
109 cause
191 grand
170 present
247 indicate
289 counter
174 we
214 like
56 visit
232 state
76 morning
288 true
41 are
273 ball
136 history
159 seat
201 rain
27 less
94 glass
75 tone
290 song
64 fair
79 element
72 speed
98 produce
66 quotient
5 sand
145 begin
150 moment
268 offer
73 probable
291 all
215 necessary
246 post
83 cent
203 happen
38 speech
163 object
297 silver
17 third
258 crease
236 wait
71 triangle
260 idea
216 clothe
168 young
235 discuss
146 field
69 company
52 capital
102 compare
248 chart
148 possible
90 written
12 remember
113 mile
293 cold
212 lady
266 felt
46 against
287 skin
121 prepare
10 he
57 card
197 organ
279 object
24 our
169 major
188 discuss
286 system
167 hole
256 above
179 they
126 produce
244 straight
104 level
26 though
206 modern
99 dry
164 bought
55 milk
108 make
80 show
281 middle
123 center
42 blood
51 speak
124 prove
190 select
178 power
143 come
100 brown
224 experiment
199 strong
138 hurry
95 touch
261 reach
141 case
43 beat
280 over
204 dry
220 hill
115 company
142 opposite
300 work
144 field
132 felt
48 prepare
262 now
158 his
45 stay
134 toward
13 observe
131 time
116 stop
184 possible
11 card
65 prepare
275 current
25 compare
243 neighbor
198 thus
283 include
193 copy
223 bit
182 stead
296 does
31 general
153 solve
176 glad
200 duck
97 offer
127 happen
86 ball
62 bread
175 like
53 machine
6 come
277 any
68 band
28 it
117 section
196 close
4 heavy
32 produce
35 got
205 possible
180 insect
103 way
257 before
40 men
239 bird
218 ease
295 trade
77 winter
30 am
181 repeat
147 first
114 to
105 each
242 guide
44 column
250 single
67 remember
276 wild
154 major
249 coast
54 class
29 done
183 jump
189 sister
285 feel
21 check
219 fire
74 nine
140 indicate
255 parent
106 whole
282 her
269 the
107 temperature
33 design
227 big
49 skill
263 friend
240 hit
2 wait
60 instant
110 blow
112 about
34 chick
39 answer
172 man
92 material
185 current
222 think
238 print
16 nor
252 better
229 example
253 people
101 drink
161 gun
228 together
177 cost
85 require
139 or
22 people
192 planet
7 ease
166 ready
118 enough
251 sugar
157 deal
202 with
265 us
195 share
19 office
14 protect
119 low
186 thus
162 farm
294 oxygen
23 fire
209 force
210 select
15 paragraph
70 always
230 poem
61 chick
128 planet
171 fact
152 moment
173 term

Repl link:

Hi @drtplewr , welcome to the forums!
Is this a school assignment?

Thanks for the warm welcome! :slight_smile: Yes this is a school assignment.

Closed for School Assignment

Now School Assignments are against the community guidelines, and are supposed to be closed according to Staff