calculator

This commit is contained in:
2025-09-08 14:36:12 +03:00
parent d1b535400e
commit 9682b2f4f4
6 changed files with 151 additions and 0 deletions

21
calculator/pkg/render.py Normal file
View File

@@ -0,0 +1,21 @@
def render(expression, result):
if isinstance(result, float) and result.is_integer():
result_str = str(int(result))
else:
result_str = str(result)
box_width = max(len(expression), len(result_str)) + 4
box = []
box.append("" + "" * box_width + "")
box.append(
"" + " " * 2 + expression + " " * (box_width - len(expression) - 2) + ""
)
box.append("" + " " * box_width + "")
box.append("" + " " * 2 + "=" + " " * (box_width - 3) + "")
box.append("" + " " * box_width + "")
box.append(
"" + " " * 2 + result_str + " " * (box_width - len(result_str) - 2) + ""
)
box.append("" + "" * box_width + "")
return "\n".join(box)