Skip to content
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eacebd7
Create Calc.py
sgindeed Oct 6, 2025
21ef5e1
Rename Calc.py to calc.py
sgindeed Oct 6, 2025
2df824d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2025
913c90a
Create rat_in_a_maze.py
sgindeed Oct 6, 2025
16b6d78
Delete dynamic_programming/rat_in_a_maze.py
sgindeed Oct 6, 2025
d0909dc
Create m-coloring-problem.py
sgindeed Oct 6, 2025
152c0c0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2025
7647b47
Rename m-coloring-problem.py to m_coloring_problem.py
sgindeed Oct 6, 2025
80cfe21
Delete other/calc.py
sgindeed Oct 6, 2025
5dba8a1
Update m_coloring_problem.py
sgindeed Oct 6, 2025
ecab4cf
Update m_coloring_problem.py
sgindeed Oct 6, 2025
8c00f5e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2025
67a6eb1
Update m_coloring_problem.py
sgindeed Oct 6, 2025
b1ae455
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2025
b8a0a74
Update m_coloring_problem.py
sgindeed Oct 6, 2025
a6a3db2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2025
a841332
Update m_coloring_problem.py
sgindeed Oct 6, 2025
15b2b7b
Update m_coloring_problem.py
sgindeed Oct 6, 2025
a729c20
Update m_coloring_problem.py
sgindeed Oct 6, 2025
96ba61e
Update m_coloring_problem.py
sgindeed Oct 6, 2025
0d3bd86
Update m_coloring_problem.py
sgindeed Oct 6, 2025
547da5e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2025
719da79
Update m_coloring_problem.py
sgindeed Oct 6, 2025
4f43023
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2025
6a5897a
Update m_coloring_problem.py
sgindeed Oct 6, 2025
18dd29f
Update m_coloring_problem.py
sgindeed Oct 6, 2025
bcc609c
Merge branch 'master' into master
sgindeed Oct 6, 2025
7e23518
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Create Calc.py
  • Loading branch information
sgindeed authored Oct 6, 2025
commit eacebd7fed6e473d12710e8fc559796e92eb5ca3
85 changes: 85 additions & 0 deletions other/Calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from flask import Flask, request, render_template_string

app = Flask(__name__)

def calculate(num1: float, num2: float, operation: str) -> float:
"""
Perform basic arithmetic operations: add, subtract, multiply, divide.

>>> calculate(2, 3, 'add')
5
>>> calculate(5, 3, 'subtract')
2
>>> calculate(4, 2, 'multiply')
8
>>> calculate(10, 2, 'divide')
5.0
>>> calculate(5, 0, 'divide')
Traceback (most recent call last):
...
ValueError: Division by zero is not allowed.
"""
if operation == "add":
return num1 + num2
elif operation == "subtract":
return num1 - num2
elif operation == "multiply":
return num1 * num2
elif operation == "divide":
if num2 == 0:
raise ValueError("Division by zero is not allowed.")
return num1 / num2
else:
raise ValueError(f"Unknown operation: {operation}")

# HTML template for the web interface
template = """
<!DOCTYPE html>
<html>
<head>
<title>Flask Calculator</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; padding: 50px; background: #f7f7f7; }
input, select { padding: 10px; margin: 5px; width: 150px; }
input[type=submit] { width: auto; cursor: pointer; }
.result { margin-top: 20px; font-size: 1.5em; color: #27ae60; }
h1 { color: #2c3e50; }
</style>
</head>
<body>
<h1>Flask Calculator</h1>
<form method="POST">
<input type="number" name="num1" step="any" placeholder="First Number" required>
<input type="number" name="num2" step="any" placeholder="Second Number" required>
<br>
<select name="operation">
<option value="add">Add (+)</option>
<option value="subtract">Subtract (-)</option>
<option value="multiply">Multiply (×)</option>
<option value="divide">Divide (÷)</option>
</select>
<br>
<input type="submit" value="Calculate">
</form>
{% if result is not none %}
<div class="result">Result: {{ result }}</div>
{% endif %}
</body>
</html>
"""

@app.route("/", methods=["GET", "POST"])
def home():
result = None
if request.method == "POST":
try:
num1 = float(request.form["num1"])
num2 = float(request.form["num2"])
op = request.form["operation"]
result = calculate(num1, num2, op)
except Exception as e:
result = str(e)
return render_template_string(template, result=result)

if __name__ == "__main__":
app.run(debug=True)