import mysql.connector def calculate_bmi(weight, height): bmi = (weight)/(height**2) def get_bmi_category(bmi): if bmi < 18.5: return "Underweight" elif bmi < 25: return "Normal" elif bmi < 30: return "Overweight" else: return "Obese" def diet_plan(category): print("\n--- DIET PLAN ---\n") if category == "Underweight": print("-> Eat more protein: eggs, chicken, paneer") print("-> Include nuts and healthy fats") print("-> Eat 5-6 meals per day") print("-> Drink milk with meals") elif category == "Normal": print("-> Maintain balanced diet") print("-> Include fruits and vegetables") print("-> Drink 8 glasses of water daily") print("-> Avoid junk food") elif category == "Overweight": print("-> Reduce rice and sugar intake") print("-> Eat more vegetables and salads") print("-> Drink green tea") print("-> Avoid fried foods") else: print("-> Focus on high protein, low carb diet") print("-> Eat lots of vegetables") print("-> Avoid sugar and oil completely") print("-> Consult a nutritionist") def workout_plan(category, age): print("\n--- WORKOUT PLAN ---\n") if category == "Underweight": print("-> Strength training: 3 days/week") print("-> Push-ups: 3 sets of 10") print("-> Squats: 3 sets of 12") print("-> Light cardio: 15 minutes") elif category == "Normal": print("-> Cardio: Running/cycling 30 min") print("-> Mix of strength and cardio") print("-> Exercise 4-5 days/week") print("-> Sports or swimming") elif category == "Overweight": print("-> Walking: 45 minutes daily") print("-> Light jogging: 20 minutes") print("-> Cycling or swimming") print("-> Exercise 5-6 days/week") else: print("-> Start with walking: 30-40 minutes") print("-> Gradually increase intensity") print("-> Avoid high impact exercises initially") print("-> Consult doctor before starting") if age > 50: print("\n*Note: Focus on low-impact exercises at your age") print("=" * 40) print(" BMI CALCULATOR & FITNESS PLANNER") print("=" * 40) name = input("\nEnter your name: ") age = int(input("Enter your age: ")) weight = float(input("Enter your weight (in kg): ")) height = float(input("Enter your height (in cm): ")) height = height / 100 bmi = calculate_bmi(weight, height) category = get_bmi_category(bmi) print("\n" + "=" * 40) print(f"\n Hello {name}!") print(f"\n Your BMI: {bmi} ") print(f"\n Category: {category}\n") print("=" * 40) diet_plan(category) workout_plan(category, age) host="localhost", user="root", password="your_password", database="fitness_db" ) mycursor = mydb.cursor() sql = "INSERT INTO bmi_records (name, age, weight, height, bmi, category) VALUES (%s, %s, %s, %s, %s, %s)" val = (name, age, weight, height, bmi, category) mycursor.execute(sql, val) mydb.commit() print(f"\n Record saved (ID: {mycursor.lastrowid})") mydb.close() print("\n" + "=" * 40) print("\n Stay healthy and fit!\n") print("=" * 40)
Standard input is empty
import mysql.connector
def calculate_bmi(weight, height):
bmi = (weight)/(height**2)
return round(bmi,2)
def get_bmi_category(bmi):
if bmi < 18.5:
return "Underweight"
elif bmi < 25:
return "Normal"
elif bmi < 30:
return "Overweight"
else:
return "Obese"
def diet_plan(category):
print("\n--- DIET PLAN ---\n")
if category == "Underweight":
print("-> Eat more protein: eggs, chicken, paneer")
print("-> Include nuts and healthy fats")
print("-> Eat 5-6 meals per day")
print("-> Drink milk with meals")
elif category == "Normal":
print("-> Maintain balanced diet")
print("-> Include fruits and vegetables")
print("-> Drink 8 glasses of water daily")
print("-> Avoid junk food")
elif category == "Overweight":
print("-> Reduce rice and sugar intake")
print("-> Eat more vegetables and salads")
print("-> Drink green tea")
print("-> Avoid fried foods")
else:
print("-> Focus on high protein, low carb diet")
print("-> Eat lots of vegetables")
print("-> Avoid sugar and oil completely")
print("-> Consult a nutritionist")
def workout_plan(category, age):
print("\n--- WORKOUT PLAN ---\n")
if category == "Underweight":
print("-> Strength training: 3 days/week")
print("-> Push-ups: 3 sets of 10")
print("-> Squats: 3 sets of 12")
print("-> Light cardio: 15 minutes")
elif category == "Normal":
print("-> Cardio: Running/cycling 30 min")
print("-> Mix of strength and cardio")
print("-> Exercise 4-5 days/week")
print("-> Sports or swimming")
elif category == "Overweight":
print("-> Walking: 45 minutes daily")
print("-> Light jogging: 20 minutes")
print("-> Cycling or swimming")
print("-> Exercise 5-6 days/week")
else:
print("-> Start with walking: 30-40 minutes")
print("-> Gradually increase intensity")
print("-> Avoid high impact exercises initially")
print("-> Consult doctor before starting")
if age > 50:
print("\n*Note: Focus on low-impact exercises at your age")
print("=" * 40)
print(" BMI CALCULATOR & FITNESS PLANNER")
print("=" * 40)
name = input("\nEnter your name: ")
age = int(input("Enter your age: "))
weight = float(input("Enter your weight (in kg): "))
height = float(input("Enter your height (in cm): "))
height = height / 100
bmi = calculate_bmi(weight, height)
category = get_bmi_category(bmi)
print("\n" + "=" * 40)
print(f"\n Hello {name}!")
print(f"\n Your BMI: {bmi} ")
print(f"\n Category: {category}\n")
print("=" * 40)
diet_plan(category)
workout_plan(category, age)
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="your_password",
database="fitness_db"
)
mycursor = mydb.cursor()
sql = "INSERT INTO bmi_records (name, age, weight, height, bmi, category) VALUES (%s, %s, %s, %s, %s, %s)"
val = (name, age, weight, height, bmi, category)
mycursor.execute(sql, val)
mydb.commit()
print(f"\n Record saved (ID: {mycursor.lastrowid})")
mydb.close()
print("\n" + "=" * 40)
print("\n Stay healthy and fit!\n")
print("=" * 40)