I am new to programming and am trying to code a simple calculator. The code takes user input, generates a list of numbers and operators (eg. 1+2/3*4) and loops over the list to perform the calculation with operator precedence.
My logic is to search for operator, get index of the numbers before and after operator, perform calculation on numbers, delete numbers used in calculation from list, delete operator from list, insert result of calculation at index of operator.
all is working well except the delete part;
def calc():
for combsym in comb:
while combsym == '*':
mulindex = comb.index(combsym)
aindex = mulindex - 1
a = comb.pop(aindex)
mulindex = comb.index(combsym)
bindex = mulindex + 1
b = comb.pop(bindex)
mul(a,b)
mulindex = comb.index(combsym)
comb.remove(mulindex)
comb.insert(mulindex, result)
I get the following error: list.remove(x): x not in list
Any suggestions?