Убрал всё лишнее, полностью переписал код без питона и вообще без бэкенда.

This commit is contained in:
dr_domi
2026-05-02 23:31:20 +03:00
parent c7220c11b0
commit 4c1fad310a
5 changed files with 173 additions and 230 deletions
-34
View File
@@ -1,34 +0,0 @@
#!/usr/bin/env python3
from flask import Flask, request, jsonify, render_template
app = Flask(__name__)
def calculate_bmi(height, weight):
return round(weight / (height ** 2), 2)
def user_input_check(height, weight):
if height <= 0 or height > 3:
return "Рост должен быть больше 0 и не превышать 3 метра."
if weight <= 0 or weight > 200:
return "Вес должен быть больше 0 и не превышать 200 кг."
return None
@app.route('/')
def index():
return render_template('index.html')
@app.route('/calculate', methods=['POST'])
def calculate():
data = request.get_json()
height = float(data['height'])
weight = float(data['weight'])
error = user_input_check(height, weight)
if error:
return jsonify({'error': error}), 400
bmi = calculate_bmi(height, weight)
return jsonify({'bmi': bmi})
if __name__ == '__main__':
app.run(debug=True)
+173
View File
@@ -0,0 +1,173 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Калькулятор BMI</title>
<style>
/* Общие стили */
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #e6f7ff;
color: #003366;
margin: 0;
padding: 0;
line-height: 1.6;
}
header {
background-color: #b3e0ff;
padding: 20px;
text-align: center;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
header h1 {
margin: 0;
font-size: 28px;
color: #003366;
}
main {
max-width: 600px;
margin: 30px auto;
padding: 20px;
background-color: #d9f0ff;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
form label {
display: block;
margin-top: 15px;
font-weight: bold;
}
form input[type="text"] {
width: 100%;
padding: 10px;
margin-top: 5px;
border: 1px solid #99d6ff;
border-radius: 5px;
font-size: 16px;
box-sizing: border-box;
}
form button {
margin-top: 20px;
padding: 12px 20px;
background-color: #0066cc;
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
form button:hover {
background-color: #004d99;
}
#result {
margin-top: 20px;
padding: 15px;
background-color: #cce6ff;
border-radius: 5px;
font-size: 18px;
font-weight: bold;
text-align: center;
display: none;
}
aside {
max-width: 600px;
margin: 20px auto;
padding: 15px;
background-color: #c2e0ff;
border-radius: 8px;
font-size: 14px;
}
aside h3 {
margin-top: 0;
color: #003366;
}
footer {
text-align: center;
padding: 20px;
background-color: #b3e0ff;
color: #003366;
font-size: 14px;
margin-top: 40px;
}
</style>
</head>
<body>
<header>
<h1>Калькулятор индекса массы тела (BMI)</h1>
</header>
<main>
<form id="bmi-form">
<label for="height">Рост (в метрах):</label>
<input type="text" id="height" name="height" placeholder="Например: 1.75" required>
<label for="weight">Вес (в килограммах):</label>
<input type="text" id="weight" name="weight" placeholder="Например: 70" required>
<button type="submit">Рассчитать BMI</button>
</form>
<div id="result"></div>
</main>
<aside>
<h3>Интерпретация результата:</h3>
<ul>
<li><strong>Менее 18.5</strong> — Недостаточный вес</li>
<li><strong>18.524.9</strong> — Нормальный вес</li>
<li><strong>2529.9</strong> — Избыточный вес</li>
<li><strong>30 и более</strong> — Ожирение</li>
</ul>
</aside>
<footer>
<p>&copy; 2025 Калькулятор BMI. Все права защищены.</p>
</footer>
<script>
document.getElementById('bmi-form').addEventListener('submit', function(e) {
e.preventDefault();
const heightInput = document.getElementById('height').value;
const weightInput = document.getElementById('weight').value;
const resultDiv = document.getElementById('result');
// Проверка на число
const height = parseFloat(heightInput);
const weight = parseFloat(weightInput);
if (isNaN(height) || isNaN(weight)) {
resultDiv.style.display = 'block';
resultDiv.style.color = '#cc0000';
resultDiv.textContent = 'Ошибка: введите корректные числа.';
return;
}
if (height <= 0 || height > 3) {
resultDiv.style.display = 'block';
resultDiv.style.color = '#cc0000';
resultDiv.textContent = 'Рост должен быть от 0.5 до 3 метров.';
return;
}
if (weight <= 0 || weight > 200) {
resultDiv.style.display = 'block';
resultDiv.style.color = '#cc0000';
resultDiv.textContent = 'Вес должен быть от 1 до 200 кг.';
return;
}
// Расчёт BMI
const bmi = weight / (height * height);
const roundedBmi = Math.round(bmi * 100) / 100;
// Отображение результата
resultDiv.style.display = 'block';
resultDiv.style.color = '#003366';
resultDiv.textContent = `Ваш BMI: ${roundedBmi}`;
});
</script>
</body>
</html>
-30
View File
@@ -1,30 +0,0 @@
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';
});
});
-109
View File
@@ -1,109 +0,0 @@
/* Общие стили страницы */
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #e6f7ff; /* Светло-голубой фон */
color: #003366; /* Тёмно-синий текст для контраста */
margin: 0;
padding: 0;
line-height: 1.6;
}
/* Шапка сайта */
header {
background-color: #b3e0ff; /* Более тёмный голубой */
padding: 20px;
text-align: center;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
header h1 {
margin: 0;
font-size: 28px;
color: #003366;
}
/* Основное содержимое */
main {
max-width: 600px;
margin: 30px auto;
padding: 20px;
background-color: #d9f0ff; /* Светло-голубой блок */
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
/* Форма ввода */
form label {
display: block;
margin-top: 15px;
font-weight: bold;
color: #003366;
}
form input[type="text"] {
width: 100%;
padding: 10px;
margin-top: 5px;
border: 1px solid #99d6ff;
border-radius: 5px;
font-size: 16px;
box-sizing: border-box;
}
form button {
margin-top: 20px;
padding: 12px 20px;
background-color: #0066cc; /* Синий цвет кнопки */
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
form button:hover {
background-color: #004d99; /* Темнее при наведении */
}
/* Блок результата */
#result {
margin-top: 20px;
padding: 15px;
background-color: #cce6ff;
border-radius: 5px;
font-size: 18px;
font-weight: bold;
text-align: center;
display: none; /* Скрыто до расчёта */
}
/* Дополнительная информация (шкала BMI) */
aside {
max-width: 600px;
margin: 20px auto;
padding: 15px;
background-color: #c2e0ff;
border-radius: 8px;
font-size: 14px;
}
aside h3 {
margin-top: 0;
color: #003366;
}
aside ul {
margin: 10px 0;
padding-left: 20px;
}
/* Подвал */
footer {
text-align: center;
padding: 20px;
background-color: #b3e0ff;
color: #003366;
font-size: 14px;
margin-top: 40px;
}
-57
View File
@@ -1,57 +0,0 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Калькулятор BMI</title>
<!-- Подключение стилей -->
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<!-- 1. Шапка сайта (заголовок, логотип, навигация) -->
<header>
<!-- Можно добавить логотип или название -->
<h1>Калькулятор индекса массы тела (BMI)</h1>
</header>
<!-- 2. Основное содержимое страницы -->
<main>
<!-- Форма для ввода данных пользователя -->
<section>
<form id="bmi-form">
<label for="height">Рост (в метрах):</label>
<input type="text" id="height" name="height" placeholder="Например: 1.75" required>
<label for="weight">Вес (в килограммах):</label>
<input type="text" id="weight" name="weight" placeholder="Например: 70" required>
<button type="submit">Рассчитать BMI</button>
</form>
<!-- Место для вывода результата -->
<div id="result">
<!-- Сюда будет вставлен результат расчёта -->
</div>
</section>
</main>
<!-- 3. Блок с информацией о результатах BMI -->
<aside>
<h3>Интерпретация результата:</h3>
<ul>
<li>Менее 18.5 — Недостаточный вес</li>
<li>18.5–24.9 — Нормальный вес</li>
<li>25–29.9 — Избыточный вес</li>
<li>30 и более — Ожирение</li>
</ul>
</aside>
<!-- 4. Подвал сайта -->
<footer>
<p>&copy; 2025 Калькулятор BMI. Все права защищены.</p>
</footer>
<!-- Подключение JavaScript-файла для обработки формы -->
<script src="{{ url_for('static', filename='script.js') }}"></script>
</body>
</html>