fork download
  1. import mysql.connector
  2.  
  3. def calculate_bmi(weight, height):
  4. bmi = (weight)/(height**2)
  5. return round(bmi,2)
  6.  
  7.  
  8. def get_bmi_category(bmi):
  9. if bmi < 18.5:
  10. return "Underweight"
  11. elif bmi < 25:
  12. return "Normal"
  13. elif bmi < 30:
  14. return "Overweight"
  15. else:
  16. return "Obese"
  17.  
  18.  
  19. def diet_plan(category):
  20. print("\n--- DIET PLAN ---\n")
  21.  
  22. if category == "Underweight":
  23. print("-> Eat more protein: eggs, chicken, paneer")
  24. print("-> Include nuts and healthy fats")
  25. print("-> Eat 5-6 meals per day")
  26. print("-> Drink milk with meals")
  27.  
  28. elif category == "Normal":
  29. print("-> Maintain balanced diet")
  30. print("-> Include fruits and vegetables")
  31. print("-> Drink 8 glasses of water daily")
  32. print("-> Avoid junk food")
  33.  
  34. elif category == "Overweight":
  35. print("-> Reduce rice and sugar intake")
  36. print("-> Eat more vegetables and salads")
  37. print("-> Drink green tea")
  38. print("-> Avoid fried foods")
  39.  
  40. else:
  41. print("-> Focus on high protein, low carb diet")
  42. print("-> Eat lots of vegetables")
  43. print("-> Avoid sugar and oil completely")
  44. print("-> Consult a nutritionist")
  45.  
  46.  
  47. def workout_plan(category, age):
  48. print("\n--- WORKOUT PLAN ---\n")
  49.  
  50. if category == "Underweight":
  51. print("-> Strength training: 3 days/week")
  52. print("-> Push-ups: 3 sets of 10")
  53. print("-> Squats: 3 sets of 12")
  54. print("-> Light cardio: 15 minutes")
  55.  
  56. elif category == "Normal":
  57. print("-> Cardio: Running/cycling 30 min")
  58. print("-> Mix of strength and cardio")
  59. print("-> Exercise 4-5 days/week")
  60. print("-> Sports or swimming")
  61.  
  62. elif category == "Overweight":
  63. print("-> Walking: 45 minutes daily")
  64. print("-> Light jogging: 20 minutes")
  65. print("-> Cycling or swimming")
  66. print("-> Exercise 5-6 days/week")
  67.  
  68. else:
  69. print("-> Start with walking: 30-40 minutes")
  70. print("-> Gradually increase intensity")
  71. print("-> Avoid high impact exercises initially")
  72. print("-> Consult doctor before starting")
  73.  
  74. if age > 50:
  75. print("\n*Note: Focus on low-impact exercises at your age")
  76.  
  77.  
  78. print("=" * 40)
  79. print(" BMI CALCULATOR & FITNESS PLANNER")
  80. print("=" * 40)
  81.  
  82.  
  83. name = input("\nEnter your name: ")
  84. age = int(input("Enter your age: "))
  85. weight = float(input("Enter your weight (in kg): "))
  86. height = float(input("Enter your height (in cm): "))
  87. height = height / 100
  88.  
  89.  
  90. bmi = calculate_bmi(weight, height)
  91. category = get_bmi_category(bmi)
  92.  
  93.  
  94. print("\n" + "=" * 40)
  95. print(f"\n Hello {name}!")
  96. print(f"\n Your BMI: {bmi} ")
  97. print(f"\n Category: {category}\n")
  98. print("=" * 40)
  99.  
  100.  
  101. diet_plan(category)
  102. workout_plan(category, age)
  103.  
  104. mydb = mysql.connector.connect(
  105. host="localhost",
  106. user="root",
  107. password="your_password",
  108. database="fitness_db"
  109. )
  110.  
  111. mycursor = mydb.cursor()
  112.  
  113. sql = "INSERT INTO bmi_records (name, age, weight, height, bmi, category) VALUES (%s, %s, %s, %s, %s, %s)"
  114. val = (name, age, weight, height, bmi, category)
  115.  
  116. mycursor.execute(sql, val)
  117. mydb.commit()
  118.  
  119. print(f"\n Record saved (ID: {mycursor.lastrowid})")
  120.  
  121. mydb.close()
  122.  
  123.  
  124. print("\n" + "=" * 40)
  125. print("\n Stay healthy and fit!\n")
  126. print("=" * 40)
  127.  
Success #stdin #stdout 0.02s 25328KB
stdin
Standard input is empty
stdout
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)