Project URL: https://www.codecademy.com/courses/learn-python-3/informationals/python3-coded-communication
alphabet = "abcdefghijklmnopqrstuvwxyz" encoded_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!" offset = 10 def caesar_cypher(encoded_message, offset): decoded_message = "" in_alphabet = 0 remainder_alphabet = 0 for i in encoded_message: if (i in alphabet) == True: try: in_alphabet += alphabet.find(i) decoded_message += alphabet[in_alphabet + offset] in_alphabet = 0 except IndexError: in_alphabet += alphabet.find(i) remainder_alphabet = ((len(alphabet) % offset) + 1) decoded_message += alphabet[remainder_alphabet] remainder_alphabet = 0 in_alphabet = 0 else: decoded_message += i return decoded_message print(caesar_cypher(encoded_message, 10))
hhy thhrh! thhs hs hn hxhmplh oh h hhhshr hhphhr. whrh you hhlh to hhhohh ht? h hoph so! shnh mh h mhsshhh hhhk whth thh shmh ohhsht!
First & foremost, please excuse what I have no doubt is likely poorly formatted, redundant code, as I am still quite new at this.
That said, as is relatively obvious, it appears as though the Except portion of my code, despite outputting the correct decoded letter the first time through, is getting stuck on said letter & re-applying it to any/all future instances when the Except portion proves relevant.
Most specifically, why does including a reset of the remainder_alphabet variable to zero not result in the correct decoded letter being applied following the first instance?
I’m sure the answer is relatively straightforward, however, after attempting to debug my code myself for an extended period of time, I’d greatly appreciate any insight any of you may be able to provide. Thanks in advance!