diff --git a/backend.py b/backend.py index 38940b7..0631dbb 100644 --- a/backend.py +++ b/backend.py @@ -1,8 +1,19 @@ -def calculate(height, wight): - result = wight / height ^ 2 - return result +def calculate(height, weight): + result = weight / (height ** 2) + return round(result, 2) -def user_input_check(height, wight): - if height.isdigit() and wight.isdigit(): - if height != 0 and wight != 0: - return True +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