Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions other/Calculator/Calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# calc.py

Check failure on line 1 in other/Calculator/Calc.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (INP001)

other/Calculator/Calc.py:1:1: INP001 File `other/Calculator/Calc.py` is part of an implicit namespace package. Add an `__init__.py`.
from flask import Flask, render_template_string, request

app = Flask(__name__)

# HTML template
template = """
<!DOCTYPE html>
<html>
<head>
<title>Flask Calculator</title>
<style>
body { font-family: Arial; background-color: #f5f5f5; text-align: center; padding: 50px; }

Check failure on line 13 in other/Calculator/Calc.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/Calculator/Calc.py:13:89: E501 Line too long (98 > 88)
input[type=number], select { padding: 10px; margin: 10px; width: 150px; }
input[type=submit] { padding: 10px 20px; margin: 10px; }
h1 { color: #2c3e50; }
.result { margin-top: 20px; font-size: 1.5em; color: #27ae60; }
</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>

Check failure on line 24 in other/Calculator/Calc.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/Calculator/Calc.py:24:89: E501 Line too long (89 > 88)
<br>
<select name="operation">
<option value="add">Add (+)</option>
<option value="subtract">Subtract (-)</option>
<option value="multiply">Multiply (×)</option>

Check failure on line 29 in other/Calculator/Calc.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (RUF001)

other/Calculator/Calc.py:29:48: RUF001 String contains ambiguous `×` (MULTIPLICATION SIGN). Did you mean `x` (LATIN SMALL LETTER X)?
<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 calculator():
result = None
if request.method == "POST":
try:
num1 = float(request.form["num1"])
num2 = float(request.form["num2"])
op = request.form["operation"]

if op == "add":
result = num1 + num2
elif op == "subtract":
result = num1 - num2
elif op == "multiply":
result = num1 * num2
elif op == "divide":
result = num1 / num2 if num2 != 0 else "Error: Division by zero"
except ValueError:
result = "Invalid input"
return render_template_string(template, result=result)

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

Check failure on line 64 in other/Calculator/Calc.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (S201)

other/Calculator/Calc.py:64:13: S201 Use of `debug=True` in Flask app detected
Loading