From c7220c11b0b9876433bca1faadf61e491d2cf938 Mon Sep 17 00:00:00 2001 From: dr_domi Date: Sat, 2 May 2026 23:26:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D1=84=D0=B8=D0=BA=D1=81=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=BC=D1=8B=D1=81=D0=BB=D1=8C?= =?UTF-8?q?,=20=D0=BF=D0=BE=D1=82=D0=BE=D0=BC=20=D0=B2=D0=B5=D1=80=D0=BD?= =?UTF-8?q?=D1=83=D1=81=D1=8C=20=D0=BA=20=D0=B8=D0=B4=D0=B5=D0=B5=20=D1=81?= =?UTF-8?q?=20=D0=B1=D1=8D=D0=BA=D0=B5=D0=BD=D0=B4=D0=BE=D0=BC=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BF=D0=B8=D1=82=D0=BE=D0=BD=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 1 + backend.py | 19 ------------------- static/script.js | 30 ++++++++++++++++++++++++++++++ styles.css => static/style.css | 0 index.html => templates/index.html | 4 ++-- 5 files changed, 33 insertions(+), 21 deletions(-) mode change 100644 => 100755 app.py delete mode 100644 backend.py create mode 100644 static/script.js rename styles.css => static/style.css (100%) rename index.html => templates/index.html (93%) diff --git a/app.py b/app.py old mode 100644 new mode 100755 index a794957..03dba53 --- a/app.py +++ b/app.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from flask import Flask, request, jsonify, render_template app = Flask(__name__) diff --git a/backend.py b/backend.py deleted file mode 100644 index 0631dbb..0000000 --- a/backend.py +++ /dev/null @@ -1,19 +0,0 @@ -def calculate(height, weight): - result = weight / (height ** 2) - return round(result, 2) - -def user_input_check(height, weight): - # Проверка, что введённые значения — числа - if not (height.replace('.', '', 1).isdigit() and weight.replace('.', '', 1).isdigit()): - return "Ошибка: введите корректные числовые значения." - - height = float(height) - weight = float(weight) - - if height <= 0 or height > 3: - return "Ошибка ввода роста. Рост должен быть больше 0 и не превышать 3 метра." - - if weight <= 0 or weight > 200: - return "Ошибка ввода веса. Вес должен быть больше 0 и не превышать 200 кг." - - return None # Успешная проверка \ No newline at end of file diff --git a/static/script.js b/static/script.js new file mode 100644 index 0000000..7c2e223 --- /dev/null +++ b/static/script.js @@ -0,0 +1,30 @@ +document.getElementById('bmi-form').addEventListener('submit', function(e) { + e.preventDefault(); + + const height = document.getElementById('height').value; + const weight = document.getElementById('weight').value; + const resultDiv = document.getElementById('result'); + + fetch('/calculate', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ height, weight }) + }) + .then(response => response.json()) + .then(data => { + if (data.error) { + resultDiv.style.display = 'block'; + resultDiv.style.color = '#cc0000'; + resultDiv.textContent = data.error; + } else { + resultDiv.style.display = 'block'; + resultDiv.style.color = '#003366'; + resultDiv.textContent = `Ваш BMI: ${data.bmi}`; + } + }) + .catch(() => { + resultDiv.style.display = 'block'; + resultDiv.textContent = 'Ошибка соединения с сервером.'; + resultDiv.style.color = '#cc0000'; + }); +}); \ No newline at end of file diff --git a/styles.css b/static/style.css similarity index 100% rename from styles.css rename to static/style.css diff --git a/index.html b/templates/index.html similarity index 93% rename from index.html rename to templates/index.html index 155c056..a7d062d 100644 --- a/index.html +++ b/templates/index.html @@ -5,7 +5,7 @@ Калькулятор BMI - + @@ -52,6 +52,6 @@ - + \ No newline at end of file