Q:

Secret code decoder not working properly?

I have wrote a simple "secret code" program that translates letters of the alphabet to a series of numbers. The encoder program I wrote works, but the decoder doesnt. Here is the code for the decoder:
print("decode")
message = input("input: ")  
encoded = ""

for char in message:
    if char == "7777":
        encoded += "a"
    elif char == "7778":
        encoded += "b"
    elif char == "7788":
        encoded += "c"
    elif char == "7888":
        encoded += "d"
    elif char == "8887":
        encoded += "e"
    ...
    elif char == "4554":
        encoded += "y"
    elif char == "4444":
        encoded += "z"
    else:
        encoded += char

print("+-----------------------------+")
print("output: ")
print(encoded)
print("+-----------------------------+")

The output is just the number, for example when I input "7777" it outputs "7777" when its supposed to output "a". Any help appreciated! Thank you!

A:

Your error is quite simple. Since you are looping over the array, you are checking each individual character, when you want to check every four characters (Which evaluate to a letter). Change your loop to:
for i in range(0, len(message), 4):

This loop now iterates over every four indices in the string, which you can then use to create a new string that represents the current word:
currentWord = message[i:i+3]

Now you should check this new variable in all of your conditions.

