I am trying to create a calculator which will solve simple equations given in reverse polish notation. I have created a function for the actual calculation functionality, calculation(), as well as a function to take the input, inputs(). To get the inputs into calculation(), I tried to make inputs() an argument for that function. The issue is I can't seem to access the inputs list inside calculation() in order to perform the calculations. I'm not sure what I'm doing wrong/if this is even allowed as I'm fairly new to python.
# sorting input into integers, operators and eventually invalids
def inputs():
operators = {'+', '-', '*', '/', '%', '='}
inputs = []
print("inputs: ", inputs)
while True:
blank = input()
if blank not in operators:
inputs.append(int(blank))
else:
inputs.append(blank)
print("inputs: ", inputs)
continue
#attempting to take inputs and use them in the calculations
def calculation(inputs):
inputs = inputs()
stack = []
for a in inputs:
if type(a) is int:
stack.append(a)
print("stack.append(a)", stack)
continue
op2, op1 = stack.pop(), stack.pop()
if a == '+': #code for addition
result = op1 + op2
stack.append(result)
#code for other operators is like above