CONVERSION
CONVERSION
stk.append(item)
def stkpop(stk):
v=stk.pop()
return v
def stkpeek(stk):
if len(stk)>0:
return stk[len(stk)-1]
else:
return '#'
def stkdisplay(stk):
for i in stk:
print(i,end=" ")
if(i=='^'):
return 6
if (i=='%'):
return 5
elif(i=='/'):
return 4
elif(i=='//'):
return 3
elif(i=='*'):
return 2
elif(i=='+'):
return 1
elif(i=='-'):
return 0
elif(i=='('):
return -1
else:
return -2
def isop(op):
if op in "%^/*+-//":
return True
else:
return False
#main
opstk=[]
exp=[]
for i in s:
if i=='(':
stkpush(opstk,i)
elif isop(i):
stkpush(exp,stkpop(opstk))
stkpush(exp,i)
elif i==")":
while isop(stkpeek(opstk)):
stkpush(exp,stkpop(opstk))
stkpop(opstk)
else:
stkpush(exp,i)
for i in opstk:
stkpush(exp,i)
stkdisplay(exp)
opcount=0
operandcount=0
for i in s:
if isop(i):
opcount=opcount+1
else:
operandcount=operandcount+1
if(operandcount-opcount)==1:
print("it is correct")
else:
print("it is incorrect")