def print_welcome_message(): print("=" * 100) print("Welcome to the Comprehensive BMI Calculator!".center(100)) print("=" * 100) def get_user_input(): while True: try: height = float(input("Enter your height in meters: ")) if height <= 0: raise ValueError("Height must be a positive number.") weight = float(input("Enter your weight in kilograms: ")) if weight <= 0: raise ValueError("Weight must be a positive number.") return height, weight except ValueError as e: print(f"Invalid input: {e}. Please try again.") def calculate_bmi(height, weight): return round(weight / (height ** 2), 2) def interpret_bmi(bmi): if bmi < 18.5: return "Underweight" elif 18.5 <= bmi < 24.9: return "Normal weight" elif 25 <= bmi < 29.9: return "Overweight" else: return "Obese" def print_bmi_result(bmi, category): print("=" * 100) print(f"Your BMI is: {bmi}") print(f"Category: {category}") print("=" * 100) def offer_recommendations(category): print("Recommendations:") if category == "Underweight": print("- Consider a balanced diet with more calories.") print("- Include protein-rich foods like nuts, dairy, and legumes.") print("- Consult a healthcare provider if needed.") print("- Track your progress regularly.") print("- Eat at regular intervals.") elif category == "Normal weight": print("- Great job! Maintain your healthy lifestyle.") print("- Stay active and eat a balanced diet.") print("- Regular health check-ups are beneficial.") print("- Stay hydrated and get enough sleep.") elif category == "Overweight": print("- Consider regular physical activity.") print("- Focus on a diet with fruits, vegetables, and lean proteins.") print("- Avoid excessive sugars and saturated fats.") print("- Try incorporating walking or cycling into your routine.") print("- Monitor your calorie intake.") elif category == "Obese": print("- Consult with a healthcare provider.") print("- Engage in regular exercise.") print("- Follow a structured diet plan.") print("=" * 50) def ask_for_retry(): while True: retry = input("Would you like to calculate another BMI? (yes/no): ").strip().lower() if retry in ["yes", "y"]: return True elif retry in ["no", "n"]: return False else: print("Please enter 'yes' or 'no'.") def main(): print_welcome_message() while True: height, weight = get_user_input() bmi = calculate_bmi(height, weight) category = interpret_bmi(bmi) print_bmi_result(bmi, category) offer_recommendations(category) if not ask_for_retry(): print("Thank you for using the BMI Calculator. Stay healthy!") break if __name__ == "__main__": main()