I am facing a problem with my code, and I cant think of a way to fix it.
Note: I am not allowed to use import in my code
the code goes as follows:
def decode(in_file, out_file):
try:
s = ""
chr_nums = []
splitlst = []
lines = []
lst = []
f = open('q4.txt','r')
for line in f:
lines = line.split()
for i in range(len(lines)):
b = str(lines[i])
for l in b:
chr_nums = chr(ord(l) - 1)
for a in chr_nums:
c =' '.join(a)
print c
except IOError:
print "Cant decipher' {"+in_file+"} 'due to an IO Error."
f.close()
The goal with this code is to replace each letter in every word to the letter before it. i.e: a is changed to z and so on.
The code has to change a file that contains this kind of text:
Uif Xiffmt po uif cvt hp spvoe boe spvoe
Uif Xiffmt po uif cvt hp spvoe boe spvoe
to this result:
The Wheels on the bus go round and round
The Wheels on the bus go round and round
this is what my for loop prints in the out_file:
T h e W h e e l s o n t h e b u s g o r o u n d a n d r o u n dT h e W h e e l s o n t h e b u s g o r o u n d a n d r o u n d
How can I get the result that I showed in the example? How can I re-join the characters to form the original order?
note2: I did try to use join, but no luck using that as well
note3: the file the code gets doesn't necessarily contain the same sentence twice.