From 33be6da57e89a9a254ec750aa12ee76a864e2ba8 Mon Sep 17 00:00:00 2001 From: Anand Date: Wed, 3 Aug 2022 21:06:22 +0530 Subject: [PATCH 1/7] Changed 07_BMR_Calculation.py --- BMI-calculator/07_BMR_Calculation.py | 102 +++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 BMI-calculator/07_BMR_Calculation.py diff --git a/BMI-calculator/07_BMR_Calculation.py b/BMI-calculator/07_BMR_Calculation.py new file mode 100644 index 0000000..d1cfeec --- /dev/null +++ b/BMI-calculator/07_BMR_Calculation.py @@ -0,0 +1,102 @@ +""" We will use Python scripts for absolute beginners + This script shows the use of BMR Calculator = Basal Metabolic Rate Calculator. + BMR gives the value of the calories which the body intakes during weight gain or weight loss. + The BMR Calculator: + # Get the Age of the user + # Get the Gender of the user + # Get the weight(Kg/lb) of the user + # Get the height(m/in") of the user + # Calculate the BMI using the formula on the basis of gender, age, height and weight + For Male: BMR= 88.362+(13.397*weight in kg/lb)+(4.799*height in cm/in")- (5.677*age in years) + For Female: BMR = 447.593+(9.247*weight in kg/ib)+(3.098*height in cm/in")- (4.330*age in years) + Also, this BMR calculator include features in Metric Units (kg,metre) & American Units (pound, inch) + +Exercise 1: Calculate the BMR (in calorie) +Exercise 2: Check if the no. of days workout the user does: + No. of Days BMR *Value Level of Intensity + 0-1 BMR*1.2 NO Exercise + 1-3 BMR*1.375 Light Exercise + 3-5 BMR*1.55 Moderate Exercise + All Day BMR*1.725 Heavy Exercise +Here there will be an implication of User-defined functions and Calling function along with if else statement. +""" + +print("*****Welcome To The BMR Calculator*****") +def __getinput_to_calculate_bmr(): + "This function gets the input from the user " + Units_of_the_user = input("Metric or American:") + if Units_of_the_user == 'Metric': + print("Enter Weight in kg and Height in meters") + elif Units_of_the_user == 'American': + print("Enter Weight in pound and Height in inches") + Weight_of_the_user = float(input("Enter the weight of the user:")) + Height_of_the_user = float(input("Enter the height of the user:")) + Gender_of_the_user = (input("Enter the gender of the user M/F:")) + Age_of_the_user = int(input("Enter the age of the user:")) + + + return Weight_of_the_user, Height_of_the_user, Age_of_the_user,Units_of_the_user, Gender_of_the_user, + +def calculate_bmr (Weight_of_the_user, Height_of_the_user, Age_of_the_user,Units_of_the_user, Gender_of_the_user): + " This function calculates the BMR in metric OR american units on the basis of gender and age " + + # Here if the Gender_of_the_user is 'M' i.e Male, then formula will be BMR_Male + if Gender_of_the_user == 'M' or 'm' and 'M'=='Metric': + BMR_Male = int(88.362 + (13.397 * Weight_of_the_user) + (4.799 * Height_of_the_user)- (5.677*Age_of_the_user)) + return BMR_Male + + # Here if the Gender_of_the_user is 'F' i.e Female, then formula will be BMR_Female + elif Gender_of_the_user == 'F' or 'f' 'F'=='Metric': + BMR_Female = int(447.593 + (9.247 * weight_of_the_user) + (3.098 * height_of_the_user)- (4.330*Age_of_the_user)) + return BMR_Female + + # Here if the Gender_of_the_user is 'M' i.e Male, and taken in American Units (Weights and Heights of the user is pound and inch respectively + # then formula will be BMR_Male + elif 'M' == 'Amr' and Units_of_the_user == 'American': + BMR_Male1 = int(88.362 + (13.397 * weight_of_the_user*2.2) + (4.799 * height_of_the_user*39.37) - (5.677 * Age_of_the_user)) + return BMR_Male1 + + # Here if the Gender_of_the_user is 'F' i.e Female, and taken in American Units (Weights and Heights of the user is taken into pound and inch respectively + # then formula will be BMR_Female + elif 'F' == 'American' and Units_of_the_user == 'American': + BMR_Female1 = int(447.593 + (9.247 * weight_of_the_user*2.2) + (3.098 * height_of_the_user*39.37) - (4.330 * Age_of_the_user)) + return BMR_Female1 + + + +def check_user_BMR_category(BMR): + "This function checks if the user's Level of Intesity is No Exercise, Light Exercise, Moderate Exercise, Heavy Weight Exercise, Severy Heavy Weight Exercise" + + "The BMR values will be calculated. Then it will be multiplied with standard numbers will categorized the level of intensity/activeness the user's lifestyle " + + "If User's BMR is: Calorific Value= BMR*Standard Numbers which will denote the intensity of the user. " + Calorific_Value = BMR*1.2 + Calorific_Value1 = BMR*1.375 + Calorific_Value2 = BMR*1.55 + Calorific_Value3 = BMR*1.725 + + if BMR>800 and BMR<=1100: + print("The Value of the calorie intake is:", Calorific_Value, "which means :No Exercise (0-1 Days)!!") + elif BMR >=1200 and BMR <=1400: + print("The Value of the calorie intake is:", Calorific_Value1, "which means : Light Exercise (1-3 Days)!!") + elif BMR >=1450 and BMR <=1700: + print("The Value of the calorie intake is:", Calorific_Value2, "which means :Moderate Exercise (3-5 Days)!!") + elif BMR>2000: + print("The Value of the calorie intake is:", Calorific_Value3, "which means :Heavy Weight Exercise (7 days)") + + + +if __name__ == "__main__": + # This calling function gets the input from the user + weight_of_the_user, height_of_the_user, Units_of_the_user, Gender_of_the_user, age_of_the_user = __getinput_to_calculate_bmr() + + # This calling function stores the BMI of the user + BMR_value = calculate_bmr(weight_of_the_user, height_of_the_user, Units_of_the_user, Gender_of_the_user,age_of_the_user) + + print("BMR of the user is :", BMR_value ) + + # This function is used to calculate the user's criteria + check_user_BMR_category(BMR_value) + + + From 472995bbfc8c69136522013bce471b24b818ac89 Mon Sep 17 00:00:00 2001 From: Anand Date: Thu, 4 Aug 2022 12:57:55 +0530 Subject: [PATCH 2/7] Updated to BMR Calculator --- BMI-calculator/Read Me.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 BMI-calculator/Read Me.txt diff --git a/BMI-calculator/Read Me.txt b/BMI-calculator/Read Me.txt new file mode 100644 index 0000000..810466a --- /dev/null +++ b/BMI-calculator/Read Me.txt @@ -0,0 +1 @@ +Updated to BMR Calculator From 332c94c7b75f27b0068c93b260aa931fe92c9090 Mon Sep 17 00:00:00 2001 From: Anand Date: Thu, 4 Aug 2022 13:47:15 +0530 Subject: [PATCH 3/7] 1. Have to add function keys of lowercase and uppercase. --- BMI-calculator/Read Me.txt | 1 - Read Me.txt | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) delete mode 100644 BMI-calculator/Read Me.txt create mode 100644 Read Me.txt diff --git a/BMI-calculator/Read Me.txt b/BMI-calculator/Read Me.txt deleted file mode 100644 index 810466a..0000000 --- a/BMI-calculator/Read Me.txt +++ /dev/null @@ -1 +0,0 @@ -Updated to BMR Calculator diff --git a/Read Me.txt b/Read Me.txt new file mode 100644 index 0000000..08d1601 --- /dev/null +++ b/Read Me.txt @@ -0,0 +1,3 @@ +Work in progress: +1. Have to add function keys of lowercase and uppercase. +2. Have to configure a file in which the variables would work like function and import to mainscript. From 80cb52802a75dff16ea7420f615aaa006c746172 Mon Sep 17 00:00:00 2001 From: Anand Date: Sun, 7 Aug 2022 23:49:32 +0530 Subject: [PATCH 4/7] Imported Config file- Facing Several Issues --- BMI-calculator/BMR/BMR_Calculator.txt | 1 + BMI-calculator/BMR/Config.ini | 4 ++ .../{07_BMR_Calculation.py => BMR/IA2-7.py} | 55 ++++++++++++------- BMI-calculator/BMR/helper.py | 38 +++++++++++++ 4 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 BMI-calculator/BMR/BMR_Calculator.txt create mode 100644 BMI-calculator/BMR/Config.ini rename BMI-calculator/{07_BMR_Calculation.py => BMR/IA2-7.py} (76%) create mode 100644 BMI-calculator/BMR/helper.py diff --git a/BMI-calculator/BMR/BMR_Calculator.txt b/BMI-calculator/BMR/BMR_Calculator.txt new file mode 100644 index 0000000..0236ba1 --- /dev/null +++ b/BMI-calculator/BMR/BMR_Calculator.txt @@ -0,0 +1 @@ +1. I had to update configparser library to this program. diff --git a/BMI-calculator/BMR/Config.ini b/BMI-calculator/BMR/Config.ini new file mode 100644 index 0000000..6c5dc1f --- /dev/null +++ b/BMI-calculator/BMR/Config.ini @@ -0,0 +1,4 @@ +Gender ={'Male':{'Metric':88.362, 'American':88.362}, 'Female': {'Metric':447.593, 'American':447.593'}} +Units = {'Male':{'Weight':13.397,'Height':4.799,'Age':5.677}, 'Female':{'Weight1':9.247, 'Height1':3.098,'Age1':4.330}} + +Conversion= {'pound':2.204,'inch':39.37} diff --git a/BMI-calculator/07_BMR_Calculation.py b/BMI-calculator/BMR/IA2-7.py similarity index 76% rename from BMI-calculator/07_BMR_Calculation.py rename to BMI-calculator/BMR/IA2-7.py index d1cfeec..2ac8ed4 100644 --- a/BMI-calculator/07_BMR_Calculation.py +++ b/BMI-calculator/BMR/IA2-7.py @@ -20,6 +20,11 @@ All Day BMR*1.725 Heavy Exercise Here there will be an implication of User-defined functions and Calling function along with if else statement. """ +import os +import configparser +import helper +subject_file = configparser.ConfigParser() + print("*****Welcome To The BMR Calculator*****") def __getinput_to_calculate_bmr(): @@ -31,36 +36,37 @@ def __getinput_to_calculate_bmr(): print("Enter Weight in pound and Height in inches") Weight_of_the_user = float(input("Enter the weight of the user:")) Height_of_the_user = float(input("Enter the height of the user:")) - Gender_of_the_user = (input("Enter the gender of the user M/F:")) + Gender_of_the_user = (input("Enter the gender of the user M/m or F/f:")).lower() Age_of_the_user = int(input("Enter the age of the user:")) - return Weight_of_the_user, Height_of_the_user, Age_of_the_user,Units_of_the_user, Gender_of_the_user, + + return Weight_of_the_user, Height_of_the_user, Age_of_the_user,Units_of_the_user, Gender_of_the_user def calculate_bmr (Weight_of_the_user, Height_of_the_user, Age_of_the_user,Units_of_the_user, Gender_of_the_user): " This function calculates the BMR in metric OR american units on the basis of gender and age " - # Here if the Gender_of_the_user is 'M' i.e Male, then formula will be BMR_Male - if Gender_of_the_user == 'M' or 'm' and 'M'=='Metric': - BMR_Male = int(88.362 + (13.397 * Weight_of_the_user) + (4.799 * Height_of_the_user)- (5.677*Age_of_the_user)) - return BMR_Male + # Here if the Gender_of_the_user is 'M' i.e Male, then formula will be: + if Gender_of_the_user == Units_of_the_user: + BMR = round(Metric + (Weight * Weight_of_the_user) + (Height * Height_of_the_user)- (Age*Age_of_the_user)) + return BMR - # Here if the Gender_of_the_user is 'F' i.e Female, then formula will be BMR_Female - elif Gender_of_the_user == 'F' or 'f' 'F'=='Metric': - BMR_Female = int(447.593 + (9.247 * weight_of_the_user) + (3.098 * height_of_the_user)- (4.330*Age_of_the_user)) - return BMR_Female + # Here if the Gender_of_the_user is 'F' i.e Female, then formula will be: + elif Gender_of_the_user == Units_of_the_user: + BMR = round(Metric + (Weight1 * weight_of_the_user) + (Height1 * height_of_the_user)- (Age1*Age_of_the_user)) + return BMR # Here if the Gender_of_the_user is 'M' i.e Male, and taken in American Units (Weights and Heights of the user is pound and inch respectively - # then formula will be BMR_Male - elif 'M' == 'Amr' and Units_of_the_user == 'American': - BMR_Male1 = int(88.362 + (13.397 * weight_of_the_user*2.2) + (4.799 * height_of_the_user*39.37) - (5.677 * Age_of_the_user)) - return BMR_Male1 + # then formula will be: + elif Gender_of_the_user == Units_of_the_user: + BMR = round(American + (Weight * weight_of_the_user*pound) + (Height * height_of_the_user*inch) - (Age * Age_of_the_user)) + return BMR # Here if the Gender_of_the_user is 'F' i.e Female, and taken in American Units (Weights and Heights of the user is taken into pound and inch respectively - # then formula will be BMR_Female - elif 'F' == 'American' and Units_of_the_user == 'American': - BMR_Female1 = int(447.593 + (9.247 * weight_of_the_user*2.2) + (3.098 * height_of_the_user*39.37) - (4.330 * Age_of_the_user)) - return BMR_Female1 + # then formula will be: + elif Gender_of_the_user == Units_of_the_user: + BMR = round(American + (Weight1 * weight_of_the_user*pound) + (Height1 * height_of_the_user*inch) - (Age1 * Age_of_the_user)) + return BMR @@ -71,12 +77,12 @@ def check_user_BMR_category(BMR): "If User's BMR is: Calorific Value= BMR*Standard Numbers which will denote the intensity of the user. " Calorific_Value = BMR*1.2 - Calorific_Value1 = BMR*1.375 + Calorific_Value1 =BMR*1.375 Calorific_Value2 = BMR*1.55 Calorific_Value3 = BMR*1.725 if BMR>800 and BMR<=1100: - print("The Value of the calorie intake is:", Calorific_Value, "which means :No Exercise (0-1 Days)!!") + print("The Value of the calorie intake is:", Calorific_Value, "which means : Minimal Exercise (1 Day)!!") elif BMR >=1200 and BMR <=1400: print("The Value of the calorie intake is:", Calorific_Value1, "which means : Light Exercise (1-3 Days)!!") elif BMR >=1450 and BMR <=1700: @@ -87,6 +93,15 @@ def check_user_BMR_category(BMR): if __name__ == "__main__": + + #subject_file.read() + with open("Config.ini") as subjectfileObj: + subject_file.write(subjectfileObj) + subjectfileObj.flush() + subjectfileObj.close() + print("subject file 'Config.ini' is created") + #print(d2.keys()) + # This calling function gets the input from the user weight_of_the_user, height_of_the_user, Units_of_the_user, Gender_of_the_user, age_of_the_user = __getinput_to_calculate_bmr() diff --git a/BMI-calculator/BMR/helper.py b/BMI-calculator/BMR/helper.py new file mode 100644 index 0000000..2c4a504 --- /dev/null +++ b/BMI-calculator/BMR/helper.py @@ -0,0 +1,38 @@ +def subject_read(): + subject_file.add_section("Gender") + subject_file.add_section("Units") + subject_file.add_section("Conversion") + subject_file.set("Gender","Male","Metric") + subject_file.set("Gender", "Male", "Metric") + subject_file.set("Unit", "Male", "Weight") + subject_file.set("Unit", "Male", "Height") + subject_file.set("Unit", "Male", "Age") + subject_file.set("Unit", "Female", "Weight1") + subject_file.set("Unit", "Female", "Height1") + subject_file.set("Unit", "Female", "Age1") + read_file = open("Config.ini", "r") + + '''with open("Config.ini") as subjectfileObj: + subject_file.write(subjectfileObj) + subjectfileObj.flush() + subjectfileObj.close() + print("subject file 'Config.ini' is created")''' + + read_file = open("Config.ini", "r") + content = read_file.read() + print("Content of the config file are:\n") + print(content) + read_file.flush() + read_file.close() + contents = read_file.read() + config = eval(contents) + Gender = config['Gender'] + Units = config['Units'] + Conversion = config['Conversion'] + print(Gender) + print(Units) + print(Conversion) + return (Gender, Units, Conversion) + print(Gender.keys()) + print(Units.keys()) + print(Conversion.keys()) \ No newline at end of file From 422a8c3384efede9dbd756821f63d3f83696b5cf Mon Sep 17 00:00:00 2001 From: Anand Date: Mon, 8 Aug 2022 21:45:35 +0530 Subject: [PATCH 5/7] Imported config file to main file --- BMI-calculator/BMR/Config.ini | 18 ++++++-- BMI-calculator/BMR/IA2-7.py | 80 +++++++++++++++++++++++------------ BMI-calculator/BMR/IA2-7.txt | 3 ++ BMI-calculator/BMR/helper.py | 56 +++++++++--------------- 4 files changed, 90 insertions(+), 67 deletions(-) create mode 100644 BMI-calculator/BMR/IA2-7.txt diff --git a/BMI-calculator/BMR/Config.ini b/BMI-calculator/BMR/Config.ini index 6c5dc1f..d8739fc 100644 --- a/BMI-calculator/BMR/Config.ini +++ b/BMI-calculator/BMR/Config.ini @@ -1,4 +1,16 @@ -Gender ={'Male':{'Metric':88.362, 'American':88.362}, 'Female': {'Metric':447.593, 'American':447.593'}} -Units = {'Male':{'Weight':13.397,'Height':4.799,'Age':5.677}, 'Female':{'Weight1':9.247, 'Height1':3.098,'Age1':4.330}} +[Male] +a = 88.362 +b = 13.397 +c = 4.799 +d = 5.677 + +[Female] +w = 447.593 +x = 9.247 +y = 3.098 +z = 4.33 + +[Conversion] +pound = 2.2 +inch = 33.397 -Conversion= {'pound':2.204,'inch':39.37} diff --git a/BMI-calculator/BMR/IA2-7.py b/BMI-calculator/BMR/IA2-7.py index 2ac8ed4..4b9aeee 100644 --- a/BMI-calculator/BMR/IA2-7.py +++ b/BMI-calculator/BMR/IA2-7.py @@ -20,16 +20,18 @@ All Day BMR*1.725 Heavy Exercise Here there will be an implication of User-defined functions and Calling function along with if else statement. """ -import os import configparser -import helper -subject_file = configparser.ConfigParser() +import pathlib +import math + + + print("*****Welcome To The BMR Calculator*****") def __getinput_to_calculate_bmr(): "This function gets the input from the user " - Units_of_the_user = input("Metric or American:") + Units_of_the_user = input("Metric or American:").lower() if Units_of_the_user == 'Metric': print("Enter Weight in kg and Height in meters") elif Units_of_the_user == 'American': @@ -45,62 +47,84 @@ def __getinput_to_calculate_bmr(): def calculate_bmr (Weight_of_the_user, Height_of_the_user, Age_of_the_user,Units_of_the_user, Gender_of_the_user): " This function calculates the BMR in metric OR american units on the basis of gender and age " + config_BMR= configparser.ConfigParser() + config_BMR.read("Config.ini") + + + x = config_BMR["Male"] + a = float(x["a"]) + b = float(x["b"]) + c = float(x["c"]) + d = float(x["d"]) + e = config_BMR["Female"] + w = float(e["w"]) + x = float(e["x"]) + y = float(e["y"]) + z = float(e["z"]) + + CV = config_BMR["Conversion"] + pound = float(CV["pound"]) + inch = float(CV["inch"]) # Here if the Gender_of_the_user is 'M' i.e Male, then formula will be: - if Gender_of_the_user == Units_of_the_user: - BMR = round(Metric + (Weight * Weight_of_the_user) + (Height * Height_of_the_user)- (Age*Age_of_the_user)) - return BMR + if Gender_of_the_user == 'M' or 'm' and 'M' == 'Metric': + BMR_Male = round((a + (b * Weight_of_the_user) + (c * Height_of_the_user)- (d*Age_of_the_user)),2) + return BMR_Male # Here if the Gender_of_the_user is 'F' i.e Female, then formula will be: - elif Gender_of_the_user == Units_of_the_user: - BMR = round(Metric + (Weight1 * weight_of_the_user) + (Height1 * height_of_the_user)- (Age1*Age_of_the_user)) - return BMR + elif Gender_of_the_user == 'F' or 'f' and 'F' == 'Metric': + BMR_Female = round((w + (x * weight_of_the_user) + (y * height_of_the_user)- (z*Age_of_the_user)),2) + return BMR_Female # Here if the Gender_of_the_user is 'M' i.e Male, and taken in American Units (Weights and Heights of the user is pound and inch respectively # then formula will be: - elif Gender_of_the_user == Units_of_the_user: - BMR = round(American + (Weight * weight_of_the_user*pound) + (Height * height_of_the_user*inch) - (Age * Age_of_the_user)) - return BMR + elif 'M' == 'American' and Units_of_the_user == 'American': + BMR_Male = round((a + (b * weight_of_the_user*pound) + (c * height_of_the_user*inch) - (d * Age_of_the_user)),2) + return BMR_Male # Here if the Gender_of_the_user is 'F' i.e Female, and taken in American Units (Weights and Heights of the user is taken into pound and inch respectively # then formula will be: - elif Gender_of_the_user == Units_of_the_user: - BMR = round(American + (Weight1 * weight_of_the_user*pound) + (Height1 * height_of_the_user*inch) - (Age1 * Age_of_the_user)) - return BMR + elif 'F' == 'American' and Units_of_the_user == 'American': + BMR_Female = round((w + (9.247 * weight_of_the_user*pound) + (y * height_of_the_user*inch) - (z * Age_of_the_user)),2) + return BMR_Female def check_user_BMR_category(BMR): + "This function checks if the user's Level of Intesity is No Exercise, Light Exercise, Moderate Exercise, Heavy Weight Exercise, Severy Heavy Weight Exercise" "The BMR values will be calculated. Then it will be multiplied with standard numbers will categorized the level of intensity/activeness the user's lifestyle " "If User's BMR is: Calorific Value= BMR*Standard Numbers which will denote the intensity of the user. " - Calorific_Value = BMR*1.2 - Calorific_Value1 =BMR*1.375 - Calorific_Value2 = BMR*1.55 - Calorific_Value3 = BMR*1.725 + '''def get_num(): + return BMR + Num=1.2 + CV=get_num()*Num + print(CV)''' + Calorific_Value = BMR * 1.2 + Calorific_Value1 = BMR * 1.375 + Calorific_Value2 = BMR * 1.55 + Calorific_Value3 = BMR * 1.725 if BMR>800 and BMR<=1100: print("The Value of the calorie intake is:", Calorific_Value, "which means : Minimal Exercise (1 Day)!!") + return BMR elif BMR >=1200 and BMR <=1400: print("The Value of the calorie intake is:", Calorific_Value1, "which means : Light Exercise (1-3 Days)!!") + return BMR elif BMR >=1450 and BMR <=1700: print("The Value of the calorie intake is:", Calorific_Value2, "which means :Moderate Exercise (3-5 Days)!!") + return BMR elif BMR>2000: print("The Value of the calorie intake is:", Calorific_Value3, "which means :Heavy Weight Exercise (7 days)") + return BMR + if __name__ == "__main__": - #subject_file.read() - with open("Config.ini") as subjectfileObj: - subject_file.write(subjectfileObj) - subjectfileObj.flush() - subjectfileObj.close() - print("subject file 'Config.ini' is created") - #print(d2.keys()) # This calling function gets the input from the user weight_of_the_user, height_of_the_user, Units_of_the_user, Gender_of_the_user, age_of_the_user = __getinput_to_calculate_bmr() @@ -108,7 +132,7 @@ def check_user_BMR_category(BMR): # This calling function stores the BMI of the user BMR_value = calculate_bmr(weight_of_the_user, height_of_the_user, Units_of_the_user, Gender_of_the_user,age_of_the_user) - print("BMR of the user is :", BMR_value ) + print("BMR of the user is :", BMR_value) # This function is used to calculate the user's criteria check_user_BMR_category(BMR_value) diff --git a/BMI-calculator/BMR/IA2-7.txt b/BMI-calculator/BMR/IA2-7.txt new file mode 100644 index 0000000..6b5bdea --- /dev/null +++ b/BMI-calculator/BMR/IA2-7.txt @@ -0,0 +1,3 @@ +1. Updated configparser library to this program. +2. Facing Major Issues in operand types. +3. Unable to defined BMR. diff --git a/BMI-calculator/BMR/helper.py b/BMI-calculator/BMR/helper.py index 2c4a504..4d54951 100644 --- a/BMI-calculator/BMR/helper.py +++ b/BMI-calculator/BMR/helper.py @@ -1,38 +1,22 @@ -def subject_read(): - subject_file.add_section("Gender") - subject_file.add_section("Units") - subject_file.add_section("Conversion") - subject_file.set("Gender","Male","Metric") - subject_file.set("Gender", "Male", "Metric") - subject_file.set("Unit", "Male", "Weight") - subject_file.set("Unit", "Male", "Height") - subject_file.set("Unit", "Male", "Age") - subject_file.set("Unit", "Female", "Weight1") - subject_file.set("Unit", "Female", "Height1") - subject_file.set("Unit", "Female", "Age1") - read_file = open("Config.ini", "r") +import configparser - '''with open("Config.ini") as subjectfileObj: - subject_file.write(subjectfileObj) - subjectfileObj.flush() - subjectfileObj.close() - print("subject file 'Config.ini' is created")''' +subject_file = configparser.ConfigParser() - read_file = open("Config.ini", "r") - content = read_file.read() - print("Content of the config file are:\n") - print(content) - read_file.flush() - read_file.close() - contents = read_file.read() - config = eval(contents) - Gender = config['Gender'] - Units = config['Units'] - Conversion = config['Conversion'] - print(Gender) - print(Units) - print(Conversion) - return (Gender, Units, Conversion) - print(Gender.keys()) - print(Units.keys()) - print(Conversion.keys()) \ No newline at end of file +subject_file.add_section("Male") +subject_file.set("Male", "a", "88.362") +subject_file.set("Male", "b", "13.397") +subject_file.set("Male", "c", "4.799") +subject_file.set("Male", "d", "5.677") + +subject_file.add_section("Female") +subject_file.set("Female", "w", "447.593") +subject_file.set("Female", "x", "9.247") +subject_file.set("Female", "y", "3.098") +subject_file.set("Female", "z", "4.33") + +subject_file["Conversion"]={ + "Pound":"2.2", + "Inch" : "33.397" + } +with open(r"Config.ini", 'w') as configfile: + subject_file.write(configfile) \ No newline at end of file From 72db56ff2bc765991e64f6ccbb47169be2e90bd4 Mon Sep 17 00:00:00 2001 From: Anand Date: Tue, 9 Aug 2022 12:49:47 +0530 Subject: [PATCH 6/7] Resolved the issues and run it succesfully --- BMI-calculator/BMR/BMR_Calculator.txt | 1 - BMI-calculator/BMR/Config.ini | 16 ----- BMI-calculator/BMR/IA2-7.txt | 3 - BMI-calculator/BMR/helper.py | 22 ------- BMI-calculator/BMR/IA2-7.py => BMR/BMR_01.py | 65 ++++++++++---------- BMR/BMR_01.txt | 1 + BMR/Config.ini | 16 +++++ BMR/helper.py | 20 ++++++ 8 files changed, 70 insertions(+), 74 deletions(-) delete mode 100644 BMI-calculator/BMR/BMR_Calculator.txt delete mode 100644 BMI-calculator/BMR/Config.ini delete mode 100644 BMI-calculator/BMR/IA2-7.txt delete mode 100644 BMI-calculator/BMR/helper.py rename BMI-calculator/BMR/IA2-7.py => BMR/BMR_01.py (65%) create mode 100644 BMR/BMR_01.txt create mode 100644 BMR/Config.ini create mode 100644 BMR/helper.py diff --git a/BMI-calculator/BMR/BMR_Calculator.txt b/BMI-calculator/BMR/BMR_Calculator.txt deleted file mode 100644 index 0236ba1..0000000 --- a/BMI-calculator/BMR/BMR_Calculator.txt +++ /dev/null @@ -1 +0,0 @@ -1. I had to update configparser library to this program. diff --git a/BMI-calculator/BMR/Config.ini b/BMI-calculator/BMR/Config.ini deleted file mode 100644 index d8739fc..0000000 --- a/BMI-calculator/BMR/Config.ini +++ /dev/null @@ -1,16 +0,0 @@ -[Male] -a = 88.362 -b = 13.397 -c = 4.799 -d = 5.677 - -[Female] -w = 447.593 -x = 9.247 -y = 3.098 -z = 4.33 - -[Conversion] -pound = 2.2 -inch = 33.397 - diff --git a/BMI-calculator/BMR/IA2-7.txt b/BMI-calculator/BMR/IA2-7.txt deleted file mode 100644 index 6b5bdea..0000000 --- a/BMI-calculator/BMR/IA2-7.txt +++ /dev/null @@ -1,3 +0,0 @@ -1. Updated configparser library to this program. -2. Facing Major Issues in operand types. -3. Unable to defined BMR. diff --git a/BMI-calculator/BMR/helper.py b/BMI-calculator/BMR/helper.py deleted file mode 100644 index 4d54951..0000000 --- a/BMI-calculator/BMR/helper.py +++ /dev/null @@ -1,22 +0,0 @@ -import configparser - -subject_file = configparser.ConfigParser() - -subject_file.add_section("Male") -subject_file.set("Male", "a", "88.362") -subject_file.set("Male", "b", "13.397") -subject_file.set("Male", "c", "4.799") -subject_file.set("Male", "d", "5.677") - -subject_file.add_section("Female") -subject_file.set("Female", "w", "447.593") -subject_file.set("Female", "x", "9.247") -subject_file.set("Female", "y", "3.098") -subject_file.set("Female", "z", "4.33") - -subject_file["Conversion"]={ - "Pound":"2.2", - "Inch" : "33.397" - } -with open(r"Config.ini", 'w') as configfile: - subject_file.write(configfile) \ No newline at end of file diff --git a/BMI-calculator/BMR/IA2-7.py b/BMR/BMR_01.py similarity index 65% rename from BMI-calculator/BMR/IA2-7.py rename to BMR/BMR_01.py index 4b9aeee..7864d0a 100644 --- a/BMI-calculator/BMR/IA2-7.py +++ b/BMR/BMR_01.py @@ -21,8 +21,7 @@ Here there will be an implication of User-defined functions and Calling function along with if else statement. """ import configparser -import pathlib -import math + @@ -32,13 +31,17 @@ def __getinput_to_calculate_bmr(): "This function gets the input from the user " Units_of_the_user = input("Metric or American:").lower() - if Units_of_the_user == 'Metric': + if Units_of_the_user == 'metric': print("Enter Weight in kg and Height in meters") - elif Units_of_the_user == 'American': + elif Units_of_the_user == 'american': print("Enter Weight in pound and Height in inches") Weight_of_the_user = float(input("Enter the weight of the user:")) Height_of_the_user = float(input("Enter the height of the user:")) Gender_of_the_user = (input("Enter the gender of the user M/m or F/f:")).lower() + if Gender_of_the_user == 'M' or 'm': + print("BMR will be calculated for male user") + elif Units_of_the_user == 'F' or 'f': + print("BMR will be calculated for female user") Age_of_the_user = int(input("Enter the age of the user:")) @@ -52,40 +55,40 @@ def calculate_bmr (Weight_of_the_user, Height_of_the_user, Age_of_the_user,Units x = config_BMR["Male"] - a = float(x["a"]) - b = float(x["b"]) - c = float(x["c"]) - d = float(x["d"]) + constant_for_male = float(x["constant_for_male"]) + weight_constant_for_male = float(x["weight_constant_for_male"]) + height_constant_for_male = float(x["height_constant_for_male"]) + age_constant_for_male = float(x["age_constant_for_male"]) e = config_BMR["Female"] - w = float(e["w"]) - x = float(e["x"]) - y = float(e["y"]) - z = float(e["z"]) + constant_for_female = float(e["constant_for_female"]) + weight_constant_for_female = float(e["weight_constant_for_female"]) + height_constant_for_female = float(e["height_constant_for_female"]) + age_constant_for_female = float(e["age_constant_for_female"]) CV = config_BMR["Conversion"] pound = float(CV["pound"]) - inch = float(CV["inch"]) + foot = float(CV["foot"]) # Here if the Gender_of_the_user is 'M' i.e Male, then formula will be: - if Gender_of_the_user == 'M' or 'm' and 'M' == 'Metric': - BMR_Male = round((a + (b * Weight_of_the_user) + (c * Height_of_the_user)- (d*Age_of_the_user)),2) + if Gender_of_the_user == 'M' or 'm' and Units_of_the_user == 'metric': + BMR_Male = round((constant_for_male + (weight_constant_for_male * Weight_of_the_user) + (height_constant_for_male * Height_of_the_user)- (age_constant_for_male*Age_of_the_user)),2) return BMR_Male # Here if the Gender_of_the_user is 'F' i.e Female, then formula will be: - elif Gender_of_the_user == 'F' or 'f' and 'F' == 'Metric': - BMR_Female = round((w + (x * weight_of_the_user) + (y * height_of_the_user)- (z*Age_of_the_user)),2) + elif Gender_of_the_user == 'F' or 'f' and Units_of_the_user == 'metric': + BMR_Female = round((constant_for_female + (weight_constant_for_female * Weight_of_the_user) + (height_constant_for_female * Height_of_the_user)- (age_constant_for_female*Age_of_the_user)),2) return BMR_Female # Here if the Gender_of_the_user is 'M' i.e Male, and taken in American Units (Weights and Heights of the user is pound and inch respectively # then formula will be: - elif 'M' == 'American' and Units_of_the_user == 'American': - BMR_Male = round((a + (b * weight_of_the_user*pound) + (c * height_of_the_user*inch) - (d * Age_of_the_user)),2) + elif Gender_of_the_user == 'M' or 'm' and Units_of_the_user == 'american': + BMR_Male = round((constant_for_male + (weight_constant_for_male * Weight_of_the_user*pound) + (height_constant_for_male * Height_of_the_user*foot) - (age_constant_for_male * Age_of_the_user)),2) return BMR_Male # Here if the Gender_of_the_user is 'F' i.e Female, and taken in American Units (Weights and Heights of the user is taken into pound and inch respectively # then formula will be: - elif 'F' == 'American' and Units_of_the_user == 'American': - BMR_Female = round((w + (9.247 * weight_of_the_user*pound) + (y * height_of_the_user*inch) - (z * Age_of_the_user)),2) + elif Gender_of_the_user == 'F' or 'f' and Units_of_the_user == 'american': + BMR_Female = round((constant_for_female + (weight_constant_for_female * Weight_of_the_user*pound) + (height_constant_for_female * Height_of_the_user*foot) - (age_constant_for_female * Age_of_the_user)),2) return BMR_Female @@ -97,15 +100,12 @@ def check_user_BMR_category(BMR): "The BMR values will be calculated. Then it will be multiplied with standard numbers will categorized the level of intensity/activeness the user's lifestyle " "If User's BMR is: Calorific Value= BMR*Standard Numbers which will denote the intensity of the user. " - '''def get_num(): - return BMR - Num=1.2 - CV=get_num()*Num - print(CV)''' - Calorific_Value = BMR * 1.2 - Calorific_Value1 = BMR * 1.375 - Calorific_Value2 = BMR * 1.55 - Calorific_Value3 = BMR * 1.725 + #For Metric and American Units Conditions + + Calorific_Value = round((BMR * 1.2),2) + Calorific_Value1 =round((BMR * 1.375),2) + Calorific_Value2 =round((BMR * 1.55),2) + Calorific_Value3 =round((BMR * 1.725),2) if BMR>800 and BMR<=1100: print("The Value of the calorie intake is:", Calorific_Value, "which means : Minimal Exercise (1 Day)!!") @@ -123,14 +123,15 @@ def check_user_BMR_category(BMR): + if __name__ == "__main__": # This calling function gets the input from the user - weight_of_the_user, height_of_the_user, Units_of_the_user, Gender_of_the_user, age_of_the_user = __getinput_to_calculate_bmr() + Weight_of_the_user, Height_of_the_user, Units_of_the_user, Gender_of_the_user, Age_of_the_user = __getinput_to_calculate_bmr() # This calling function stores the BMI of the user - BMR_value = calculate_bmr(weight_of_the_user, height_of_the_user, Units_of_the_user, Gender_of_the_user,age_of_the_user) + BMR_value = calculate_bmr(Weight_of_the_user, Height_of_the_user, Units_of_the_user, Gender_of_the_user,Age_of_the_user) print("BMR of the user is :", BMR_value) diff --git a/BMR/BMR_01.txt b/BMR/BMR_01.txt new file mode 100644 index 0000000..8d65329 --- /dev/null +++ b/BMR/BMR_01.txt @@ -0,0 +1 @@ +1. Added configparser library to this program. diff --git a/BMR/Config.ini b/BMR/Config.ini new file mode 100644 index 0000000..70d7ca3 --- /dev/null +++ b/BMR/Config.ini @@ -0,0 +1,16 @@ +[Male] +constant_for_male = 88.362 +weight_constant_for_male = 13.397 +height_constant_for_male = 4.799 +age_constant_for_male = 5.677 + +[Female] +constant_for_female = 447.593 +weight_constant_for_female = 9.247 +height_constant_for_female = 3.098 +age_constant_for_female = 4.33 + +[Conversion] +pound = 2.204 +foot = 3.28 + diff --git a/BMR/helper.py b/BMR/helper.py new file mode 100644 index 0000000..5dfaad1 --- /dev/null +++ b/BMR/helper.py @@ -0,0 +1,20 @@ +import configparser + +subject_file = configparser.ConfigParser() + +subject_file.add_section("Male") +subject_file.set("Male", "Constant_For_Male", "88.362") +subject_file.set("Male", "Weight_Constant_For_Male", "13.397") +subject_file.set("Male", "Height_Constant_For_Male", "4.799") +subject_file.set("Male", "Age_Constant_For_Male", "5.677") + +subject_file.add_section("Female") +subject_file.set("Female", "Constant_For_Female", "447.593") +subject_file.set("Female", "Weight_Constant_For_Female", "9.247") +subject_file.set("Female", "Height_Constant_For_Female", "3.098") +subject_file.set("Female", "Age_Constant_For_Female", "4.33") + +subject_file["Conversion"]={"Pound":"2.204","foot" : "3.28"} + +with open(r"Config.ini", 'w') as configfile: + subject_file.write(configfile) \ No newline at end of file From 1b4f80a631ab2da7c1d1006e4e015b08dab0cb8a Mon Sep 17 00:00:00 2001 From: Anand Date: Wed, 10 Aug 2022 17:08:04 +0530 Subject: [PATCH 7/7] Updated the file --- BMR/{BMR_01.py => BMR_Calculator_01.py} | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) rename BMR/{BMR_01.py => BMR_Calculator_01.py} (93%) diff --git a/BMR/BMR_01.py b/BMR/BMR_Calculator_01.py similarity index 93% rename from BMR/BMR_01.py rename to BMR/BMR_Calculator_01.py index 7864d0a..2729b7c 100644 --- a/BMR/BMR_01.py +++ b/BMR/BMR_Calculator_01.py @@ -6,13 +6,15 @@ # Get the Gender of the user # Get the weight(Kg/lb) of the user # Get the height(m/in") of the user - # Calculate the BMI using the formula on the basis of gender, age, height and weight + # Calculate the BMR using the formula on the basis of gender, age, height and weight For Male: BMR= 88.362+(13.397*weight in kg/lb)+(4.799*height in cm/in")- (5.677*age in years) For Female: BMR = 447.593+(9.247*weight in kg/ib)+(3.098*height in cm/in")- (4.330*age in years) Also, this BMR calculator include features in Metric Units (kg,metre) & American Units (pound, inch) -Exercise 1: Calculate the BMR (in calorie) -Exercise 2: Check if the no. of days workout the user does: +Exercise 1: Create a config file in helper.py and then import it into this main script. +Exercise 2: Calculate the BMR (in calorie) +Exercise 4: On this basis of BMR result, calculate how much calorie intake you shall need for exercise. +Exercise 3: Check if the no. of days of workout the user does: No. of Days BMR *Value Level of Intensity 0-1 BMR*1.2 NO Exercise 1-3 BMR*1.375 Light Exercise @@ -21,13 +23,9 @@ Here there will be an implication of User-defined functions and Calling function along with if else statement. """ import configparser +print("*****Welcome To The BMR Calculator*****") - - - - -print("*****Welcome To The BMR Calculator*****") def __getinput_to_calculate_bmr(): "This function gets the input from the user " Units_of_the_user = input("Metric or American:").lower() @@ -43,11 +41,9 @@ def __getinput_to_calculate_bmr(): elif Units_of_the_user == 'F' or 'f': print("BMR will be calculated for female user") Age_of_the_user = int(input("Enter the age of the user:")) - - - return Weight_of_the_user, Height_of_the_user, Age_of_the_user,Units_of_the_user, Gender_of_the_user + def calculate_bmr (Weight_of_the_user, Height_of_the_user, Age_of_the_user,Units_of_the_user, Gender_of_the_user): " This function calculates the BMR in metric OR american units on the basis of gender and age " config_BMR= configparser.ConfigParser() @@ -92,7 +88,6 @@ def calculate_bmr (Weight_of_the_user, Height_of_the_user, Age_of_the_user,Units return BMR_Female - def check_user_BMR_category(BMR): "This function checks if the user's Level of Intesity is No Exercise, Light Exercise, Moderate Exercise, Heavy Weight Exercise, Severy Heavy Weight Exercise" @@ -119,9 +114,8 @@ def check_user_BMR_category(BMR): elif BMR>2000: print("The Value of the calorie intake is:", Calorific_Value3, "which means :Heavy Weight Exercise (7 days)") return BMR - - - + else: + print("The Value of the BMR is too low which means you should start exercise from today itself!!") if __name__ == "__main__":