Unexpected output in code | Coded Correspondence

Hey everyone, I was just working through the Python course’s strings off-platform project, Coded Correspondence on Jupyter Notebook. However, I got stuck in the very first part. I wrote a caesar cipher function before in C, and I followed a similar method I did before but to no avail. I get an output I don’t expect. Can someone help me understand what it is that I am doing wrong?
Here’s my code:

message = '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!'
for index in range(len(message)):
    if message[index].isalpha():
        asc_val = ord(message[index])
        new_asc = asc_val + 10
        if new_asc > ord('z'):
            new_asc -= 26
            new_char = chr(new_asc)
        else:
            new_char = chr(new_asc)
        message = message.replace(message[index], new_char)

print(message)

Thanks for sharing your code!

I think a more precise question is: Where is it that your data flow isn’t acting as expected?

Set up tracing points (like formatted print statements) to make sure the values are acting as you want. Then you can deduce whether it’s imprecise use of a function, or you chose the wrong function for what you needed.

2 Likes