Stacks and Queues
Please provide the code. Thank you! And also provide the given steps in a table form
A. Create a program that will separate the operators from the operand entered by the user. Use stacks and operators will be limited with +,-, /, and *.
Sample Input: 1+2/3 * 4+5
input_str = input('Input string: ')
operators = '+-/*'
operators_stack = []
operand_stack = []
for c in input_str:
if c in operators:
operators_stack.append(c)
elif c.isdecimal() or c.isalpha():
operand_stack.append(c)
print('Operands: ', operand_stack)
print('operators: ', operators_stack)
Comments
Leave a comment