Compare commits

6 Commits

4 changed files with 94 additions and 202 deletions
-33
View File
@@ -1,33 +0,0 @@
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)
-19
View File
@@ -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 # Успешная проверка
+94 -41
View File
@@ -2,56 +2,109 @@
<html lang="ru"> <html lang="ru">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>Калькулятор BMI</title> <title>Калькулятор BMI</title>
<!-- Подключение стилей --> <!-- VK Bridge для работы внутри ВК -->
<link rel="stylesheet" href="style.css"> <script src="https://unpkg.com/@vkontakte/vk-bridge/dist/browser.min.js"></script>
<style>
:root {
--bg: #ffffff; --text: #000000; --card: #f0f2f5;
--btn: #0077ff; --btn-text: #ffffff; --border: #dce1e6;
}
@media (prefers-color-scheme: dark) {
:root { --bg: #19191a; --text: #ffffff; --card: #2c2d2e; --border: #454647; }
}
body {
margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Roboto', sans-serif;
background: var(--bg); color: var(--text); padding: 16px;
padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
}
.container { max-width: 400px; margin: 0 auto; }
h1 { font-size: 20px; margin: 0 0 16px; }
label { display: block; margin-bottom: 4px; font-weight: 500; font-size: 14px; }
input {
width: 100%; padding: 10px; margin-bottom: 12px; border: 1px solid var(--border);
border-radius: 8px; font-size: 16px; box-sizing: border-box; background: var(--bg); color: var(--text);
}
button {
width: 100%; padding: 12px; background: var(--btn); color: var(--btn-text);
border: none; border-radius: 8px; font-size: 16px; cursor: pointer; font-weight: 500;
}
button:active { opacity: 0.8; }
.result {
margin-top: 16px; padding: 12px; background: var(--card); border-radius: 8px;
display: none; line-height: 1.4;
}
.scale { margin-top: 12px; font-size: 13px; line-height: 1.5; color: var(--text); opacity: 0.85; }
.footer { margin-top: 24px; font-size: 11px; opacity: 0.6; text-align: center; line-height: 1.4; }
</style>
</head> </head>
<body> <body>
<!-- 1. Шапка сайта (заголовок, логотип, навигация) --> <div class="container">
<header>
<!-- Можно добавить логотип или название -->
<h1>Калькулятор индекса массы тела (BMI)</h1> <h1>Калькулятор индекса массы тела (BMI)</h1>
</header>
<!-- 2. Основное содержимое страницы --> <label for="height">Рост (в метрах):</label>
<main> <input type="number" id="height" placeholder="1.75" step="0.01">
<!-- Форма для ввода данных пользователя -->
<section>
<form id="bmi-form">
<label for="height">Рост (в метрах):</label>
<input type="text" id="height" name="height" placeholder="Например: 1.75" required>
<label for="weight">Вес (в килограммах):</label> <label for="weight">Вес (в килограммах):</label>
<input type="text" id="weight" name="weight" placeholder="Например: 70" required> <input type="number" id="weight" placeholder="70" step="0.1">
<button type="submit">Рассчитать BMI</button> <button onclick="calculate()">Рассчитать BMI</button>
</form>
<!-- Место для вывода результата --> <div class="result" id="result"></div>
<div id="result">
<!-- Сюда будет вставлен результат расчёта -->
</div>
</section>
</main>
<!-- 3. Блок с информацией о результатах BMI --> <div class="scale">
<aside> <b>Интерпретация результата:</b><br>
<h3>Интерпретация результата:</h3> • Менее 18.5 — Недостаточный вес<br>
<ul> • 18.5–24.9 — Нормальный вес<br>
<li>Менее 18.5 — Недостаточный вес</li> • 2529.9 — Избыточный вес<br>
<li>18.5–24.9 — Нормальный вес</li> • 30 и более — Ожирение
<li>25–29.9 — Избыточный вес</li> </div>
<li>30 и более — Ожирение</li>
</ul>
</aside>
<!-- 4. Подвал сайта --> <div class="footer">
<footer> © 2026 Калькулятор BMI. Автор: Александр Захаров.<br>
<p>&copy; 2025 Калькулятор BMI. Все права защищены.</p> Разработано с использованием GigaCode — ИИ-ассистента для программистов от Сбера.<br>
</footer> Инструмент для оценки массы тела. Не является медицинским диагнозом.
</div>
</div>
<!-- Подключение JavaScript-файла для обработки формы --> <script>
<script src="script.js"></script> // 1. Сообщаем ВК, что приложение готово
vkBridge.send('VKWebAppInit').catch(console.error);
// 2. Синхронизируем тему (светлая/тёмная) с настройками ВК
vkBridge.subscribe((e) => {
if (e.detail.type === 'VKWebAppUpdateConfig') {
const isDark = e.detail.data.theme === 'dark' || e.detail.data.theme === 'space_gray';
document.documentElement.style.setProperty('--bg', isDark ? '#19191a' : '#ffffff');
document.documentElement.style.setProperty('--text', isDark ? '#ffffff' : '#000000');
document.documentElement.style.setProperty('--card', isDark ? '#2c2d2e' : '#f0f2f5');
document.documentElement.style.setProperty('--border', isDark ? '#454647' : '#dce1e6');
}
});
// 3. Логика калькулятора
function calculate() {
const h = parseFloat(document.getElementById('height').value.replace(',', '.'));
const w = parseFloat(document.getElementById('weight').value.replace(',', '.'));
const resBox = document.getElementById('result');
if (isNaN(h) || isNaN(w) || h <= 0 || w <= 0) {
resBox.style.display = 'block';
resBox.textContent = '❌ Введите корректные рост и вес.';
return;
}
const bmi = (w / (h * h)).toFixed(1);
let status = '';
if (bmi < 18.5) status = '🔹 Недостаточный вес';
else if (bmi < 25) status = '✅ Нормальный вес';
else if (bmi < 30) status = '⚠️ Избыточный вес';
else status = '🚨 Ожирение';
resBox.style.display = 'block';
resBox.innerHTML = `<b>Ваш BMI: ${bmi}</b><br>${status}`;
}
</script>
</body> </body>
</html> </html>
-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;
}