Help me in solving ENCMSG problem

My issue

def encode(T,t):
results=
for c in t:
length,string=c
swap=list(string)
for i in range(0,length-1,2):
swap[i],swap[i+1]=swap[i+1],swap[i]
encode_msg=
for ch in swap:
opp_ch=chr(219-ord(ch))
encode_msg.append(opp_ch)
results.append(“”.join(encode_msg))
return results
T=int(input())
t=
for _ in range(T):
length=int(input())
string=input()
t.append((length,string))
results=encode(T,t)
for result in results:
print(result)
it was showing run time error can someone plese help to explain why it was runtime error

My code

def encode(T,t):
    results=[]
    for c in t:
        length,string=c 
        swap=list(string)
        for i in range(0,length-1,2):
            swap[i],swap[i+1]=swap[i+1],swap[i]
            encode_msg=[]
            for ch in swap:
                opp_ch=chr(219-ord(ch))
                encode_msg.append(opp_ch)
        results.append("".join(encode_msg))
    return results
T=int(input())
t=[]
for _ in range(T):
    length=int(input())
    string=input()
    t.append((length,string))
results=encode(T,t)
for result in results:
    print(result)

Learning course: Roadmap to 3*
Problem Link: https://www.codechef.com/learn/course/klu-roadmap-3star/KLURMP300A/problems/ENCMSG