chapter 2.1 calculator project setup

This commit is contained in:
2025-07-31 16:31:52 +02:00
parent f9a9c430e8
commit 3fb2ef23bf
4 changed files with 155 additions and 0 deletions

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

@@ -0,0 +1,23 @@
# render.py
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)