aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2025-08-14 18:27:42 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2025-08-14 18:27:42 +0200
commit68e165c323f61d008fad71d85f8e1c7f6148221f (patch)
tree6ed0cbd1ecd06161dd9ade626432e9055eeae3d4
parent3d4a2eb7dde2339697f6a5700c6017c6faf16b86 (diff)
add `ans` variable for previous answer to calculator toy
-rwxr-xr-x.local/share/bin/=32
1 files changed, 29 insertions, 3 deletions
diff --git a/.local/share/bin/= b/.local/share/bin/=
index dd8ba6c..8f3345d 100755
--- a/.local/share/bin/=
+++ b/.local/share/bin/=
@@ -1,7 +1,25 @@
#!/bin/python3 --
from sys import argv as _argv
-
+from os import environ as _environ, path as _path
from math import *
+
+_ans_path = _path.join(_environ["XDG_CACHE_HOME"], "calc_ans")
+try:
+ _ans_file = open(_ans_path, "r+")
+except:
+ _ans_file = open(_ans_path, "w+")
+_exit_code = 0
+
+ans = 0
+try:
+ _ans_str = _ans_file.read()
+ if "." in _ans_str:
+ ans = float(_ans_str)
+ else:
+ ans = int(_ans_str)
+except:
+ pass
+
deg = pi / 180
MIN = min
@@ -10,7 +28,15 @@ BIT = lambda n: 1 << n
GENMASK = lambda h, l: (BIT(MAX(h, l) + 1) - 1) ^ (BIT(MIN(h, l)) - 1)
try:
- print(eval(" ".join(_argv[1:])))
+ ans = eval(" ".join(_argv[1:]))
+ print(ans)
except:
- exit(1)
+ pass
+
+_ans_file.truncate(0)
+_ans_file.seek(0)
+_ans_file.write(str(ans))
+_ans_file.close()
+
+exit(_exit_code)