Coded_correspondence

https://www.codecademy.com/courses/learn-python-3/informationals/python3-coded-communication

can somebody tell me why my code is not working.

def decoder(message, offset):
    abc="abcdefghijklmnopqrstuvwxyz"
    for i in range(len(abc)):
        
            x=abc[i]
            y=abc[(i+offset)%26]
            message.replace(x,y)
            
    return message
        
x=decoder("""xuo jxuhu! jxyi yi qd unqcfbu ev q squiqh syfxuh. muhu oek qrbu je tusetu yj? y xefu ie! iudt cu q cuiiqwu rqsa myjx jxu iqcu evviuj!
""",10)
print(x)

output is coming - xuo jxuhu! jxyi yi qd unqcfbu ev q squiqh syfxuh. muhu oek qrbu je tusetu yj? y xefu ie! iudt cu q cuiiqwu rqsa myjx jxu iqcu evviuj!
same as message

Is this something you can carry out with pen and paper?
If you looked at what was being done, and this was the result, would you be able to tell what was done wrong?
Is there anything stopping you from looking at what is being done in your program?

Yeah the result is wrong. But what did you do to get it? That’d be something you can investigate.

So for example, you could write out what you’ve got after each change you make:

input:
xuo jxuhu! jxyi yi qd unqcfbu ev q squiqh syfxuh. muhu oek qrbu je tusetu yj? y xefu ie! iudt cu q cuiiqwu rqsa myjx jxu iqcu evviuj!

a is now k:
xuo jxuhu! jxyi yi qd unqcfbu ev q squiqh syfxuh. muhu oek qrbu je tusetu yj? y xefu ie! iudt cu q cuiiqwu rqsk myjx jxu iqcu evviuj!

b is now l:
xuo jxuhu! jxyi yi qd unqcflu ev q squiqh syfxuh. muhu oek qrlu je tusetu yj? y xefu ie! iudt cu q cuiiqwu rqsk myjx jxu iqcu evviuj!

c is now m:
xuo jxuhu! jxyi yi qd unqmflu ev q squiqh syfxuh. muhu oek qrlu je tusetu yj? y xefu ie! iudt mu q muiiqwu rqsk myjx jxu iqmu evviuj!

d is now n:
xuo jxuhu! jxyi yi qn unqmflu ev q squiqh syfxuh. muhu oek qrlu je tusetu yj? y xefu ie! iunt mu q muiiqwu rqsk myjx jxu iqmu evviuj!

e is now o:
xuo jxuhu! jxyi yi qn unqmflu ov q squiqh syfxuh. muhu ook qrlu jo tusotu yj? y xofu io! iunt mu q muiiqwu rqsk myjx jxu iqmu ovviuj!

f is now p:
xuo jxuhu! jxyi yi qn unqmplu ov q squiqh sypxuh. muhu ook qrlu jo tusotu yj? y xopu io! iunt mu q muiiqwu rqsk myjx jxu iqmu ovviuj!

g is now q:
xuo jxuhu! jxyi yi qn unqmplu ov q squiqh sypxuh. muhu ook qrlu jo tusotu yj? y xopu io! iunt mu q muiiqwu rqsk myjx jxu iqmu ovviuj!

h is now r:
xuo jxuru! jxyi yi qn unqmplu ov q squiqr sypxur. muru ook qrlu jo tusotu yj? y xopu io! iunt mu q muiiqwu rqsk myjx jxu iqmu ovviuj!

i is now s:
xuo jxuru! jxys ys qn unqmplu ov q squsqr sypxur. muru ook qrlu jo tusotu yj? y xopu so! sunt mu q mussqwu rqsk myjx jxu sqmu ovvsuj!

j is now t:
xuo txuru! txys ys qn unqmplu ov q squsqr sypxur. muru ook qrlu to tusotu yt? y xopu so! sunt mu q mussqwu rqsk mytx txu sqmu ovvsut!

k is now u:
xuo txuru! txys ys qn unqmplu ov q squsqr sypxur. muru oou qrlu to tusotu yt? y xopu so! sunt mu q mussqwu rqsk mytx txu sqmu ovvsut!

l is now v:
xuo txuru! txys ys qn unqmplu ov q squsqr sypxur. muru oou qrlu to tusotu yt? y xopu so! sunt mu q mussqwu rqsk mytx txu sqmu ovvsut!

m is now w:
xuo txuru! txys ys qn unqmplu ov q squsqr sypxur. wuru oou qrlu to tusotu yt? y xopu so! sunt mu q mussqwu rqsk wytx txu sqmu ovvsut!

n is now x:
xuo txuru! txys ys qn uxqmplu ov q squsqr sypxur. wuru oou qrlu to tusotu yt? y xopu so! sunt mu q mussqwu rqsk wytx txu sqmu ovvsut!

o is now y:
xuy txuru! txys ys qn uxqmplu ov q squsqr sypxur. wuru you qrlu to tusotu yt? y xopu so! sunt mu q mussqwu rqsk wytx txu sqmu ovvsut!

p is now z:
xuy txuru! txys ys qn uxqmplu ov q squsqr sypxur. wuru you qrlu to tusotu yt? y xopu so! sunt mu q mussqwu rqsk wytx txu sqmu ovvsut!

q is now a:
xuy txuru! txys ys an uxamplu ov a sausar sypxur. wuru you arlu to tusotu yt? y xopu so! sunt mu a mussawu rask wytx txu samu ovvsut!

r is now b:
xuy txuru! txys ys an uxamplu ov a sausar sypxur. wuru you ablu to tusotu yt? y xopu so! sunt mu a mussawu bask wytx txu samu ovvsut!

s is now c:
xuy txuru! txys ys an uxamplu ov a causar cypxur. wuru you ablu to tucotu yt? y xopu so! sunt mu a mussawu back wytx txu samu ovvsut!

t is now d:
xuy txuru! txys ys an uxamplu ov a causar cypxur. wuru you ablu to ducodu yt? y xopu so! sund mu a mussawu back wytx txu samu ovvsut!

u is now e:
xey txere! txys ys an example ov a caesar cypxer. were you able to decode yt? y xope so! send me a messawe back wytx txe same ovvset!

v is now f:
xey txere! txys ys an example of a caesar cypxer. were you able to decode yt? y xope so! send me a messawe back wytx txe same offset!

w is now g:
xey txere! txys ys an example of a caesar cypxer. were you able to decode yt? y xope so! send me a message back wytx txe same offset!

x is now h:
hey there! thys ys an example of a caesar cypher. were you able to decode yt? y hope so! send me a message back wyth the same offset!

y is now i:
hey there! this is an example of a caesar cipher. were you able to decode it? i hope so! send me a message back with the same offset!

z is now j:
hey there! this is an example of a caesar cipher. were you able to decode it? i hope so! send me a message back with the same offset!

i think after debugging by printing i,x,y .
i think i am doing mistake in “message.replace(x,y)”
which i am finding hard to understand, .replace works fine just to replace 2 characters, here when i am feeding 2 characters its not working

It would probably be a good idea to avoid the word “working”
it’s better if you describe what something does or does not do, otherwise you risk dismissing the information you need

it seems unlikely that str.replace is “not working”, you’re probably using it differently from when it does “work”

what does str.replace promise to do? what’s the input, what’s the output, what input are you giving it, and what output do you get back?

another thing.

you change a to k, then k to u, and finally u to e
so,
a becomes e
k becomes e
u becomes e

that strategy won’t work out, even after fixing bugs in the implementation

so is .replace not applicable here.
when i input a word as input to .replace like ‘hello world’.replace(‘h’,‘j’)
it worked ,so i hoped that if i input a long string and replace each alphabet one by one with its corresponding offset value it might work

you can use a long string. doesn’t matter.

you’re still using the word “work” though. you need to compare what you’re doing in both cases, not just “work” or “not work” because then you can’t tell the difference

essentially what you need to figure out is how to call a function.
you have some function, it’s doing its job, but you’re not sure how to get the result. well, where does the result go…?

:sweat_smile: i am using message.replace()
and i guess the mistake i am making is that .replace doesn’t change the original string.
thanks.