Can somebody help me with this code infix to postfix I'm getting nzec

t=int(input())
def infixtopostfix(s):
prior={’+’:1,’-’:1,’*’:2,’/’:3,’^’:4}
stack=[]
if len(s)<=1:
return s
postfixexpr=""
for i in range(len(s)):
if(s[i]==’(’):
stack.append(s[i])
elif(s[i].isalnum()):
postfixexpr+=s[i]
else:
if(s[i]==’)’):
while(len(stack)>0):
temp=stack.pop()
if(temp==’(’):
break
postfixexpr+=temp
else:
while(len(stack)!=0 and stack[-1]!=’(’ and prior[stack[-1]]>=prior[s[i]]):
postfixexpr+=stack.pop()
stack.append(s[i])
while(len(stack)!=0):
postfixexpr+=stack.pop()
return postfixexpr
for i in range(t):
n=int(input())
s=input()
print(infixtopostfix(s))

Please share a link to your solution or format it :slightly_smiling_face: :+1:

1 Like

got it!! all i had to do was input().strip() and it got accepted!! :sweat_smile: :sweat_smile:

:clap: :+1: