summaryrefslogtreecommitdiff
path: root/comp/work/54/rpn.py
diff options
context:
space:
mode:
authorthing1 <thing1@seacrossedlovers.xyz>2025-04-02 10:26:21 +0000
committerthing1 <thing1@seacrossedlovers.xyz>2025-04-02 10:26:21 +0000
commitfef6d2cc76518eee75fc0d95e765bd2be8a660ee (patch)
treed9886424f7d18d86ad1f4c73613b7e23b64b0434 /comp/work/54/rpn.py
parent5b73c7157aad4d65eee7af41fd4b4ded1a434b96 (diff)
did comp sci and some electronics
Diffstat (limited to 'comp/work/54/rpn.py')
-rw-r--r--comp/work/54/rpn.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/comp/work/54/rpn.py b/comp/work/54/rpn.py
new file mode 100644
index 0000000..053a256
--- /dev/null
+++ b/comp/work/54/rpn.py
@@ -0,0 +1,21 @@
+def eval(expr):
+ s = []
+ for i in expr.split():
+ if i.isdigit():
+ s.push(int(i))
+ else:
+ a = s.pop()
+ b = s.pop()
+ match i:
+ case '+':
+ s.push(b + a)
+ case '-':
+ s.push(b - a)
+ case '*':
+ s.push(b * a)
+ case '/':
+ s.push(b / a)
+
+ print(s.pop())
+
+eval("1 2 +")