here’s my code:
def encode(pattern, filename):
pattern = ['a','e','s','3']
message = open(filename, 'r+')
for letter in message:
if letter == pattern[0]:
letter == pattern[1]
elif letter == pattern[1]:
letter == pattern[0]
elif letter == pattern[2]:
letter == pattern[3]
else:
continue
message.close()
probably a few flaws in the code as I’m only an amateur at python, but when i run the function, the file remains unchanged. what am i doing wrong?
there is a difference between
==and=.==is used to test if two objects or primitives are the same,=is used to assign values to objects or primitives.try making these changes:
but this just assigns a value to
letterwhich will be changed the next iteration through the loop, what you really want to do is write to some other file, or write back tomessage(but this could be dangerous since you are reading from it).