Files
dsa-tutoring/notes-and-examples/2026.04.08/homework.py

15 lines
508 B
Python

# Make a calculator using Reverse Polish Notation. Use recursion.
# The Reverse Polish syntax completely removes the need for parentheses.
#
# Syntax examples:
# "3 + 2" -> ["3", "2", "+"]
# "3 * 4 + 2" -> ["3", "4", "*", "2", "+"]
# "3 * (4 + 2)" -> ["3", "4", "2", "+", "*"]
#
# Example for how to evaluate ["3", "4", "2", "+", "*"]:
# Start with "4 2 +" -> "6"
# Then "3 6 *" -> "18"
# Start with the "innermost" expression and work backwards (this is the recursion part)
#
# For help, email me@bchen.dev