Answer to Question #201511 in Python for Regina

Question #201511

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



1
Expert's answer
2021-06-01T15:00:47-0400
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS