Help with code -> global declaration
Hi, I have the following piece of code: #Create a function that intakes a simple arithmetic calculation and produces the answer import operator ops={'+':operator.add,'-':operator.sub,'*':operator.mul,'/':operator.truediv} q_calc=str(input()) def calculator(calculation): l_calc=list(calculation) for num in range(0,len(calculation)-1): if l_calc[num]=='+' or l_calc[num]=='-' or l_calc[num]=='/' or l_calc[num]=='*': num1=l_calc[:num-1] num2=l_calc[num+1:] num1=''.join(num1) num2=''.join(num2) num1=int(num1) num2=int(num2) change=l_calc[num] change=str(''.join(change)) else: print() global change print(ops[change](num1,num2)) calculator(q_calc) This creates a calculator that can do simple operations. However, when it comes to running the code, the following message appears: 'SyntaxWarning: name 'change' is assigned to before global declaration'. This is referencing the line before the penultimate line of code. Please can I have some help in how to fix this and what has gone wrong.