From 33be6da57e89a9a254ec750aa12ee76a864e2ba8 Mon Sep 17 00:00:00 2001 From: Anand Date: Wed, 3 Aug 2022 21:06:22 +0530 Subject: [PATCH 01/13] 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 02/13] 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 03/13] 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 04/13] 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 05/13] 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 06/13] 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 c0f96f75c35819662b3f4191a256d5f824e12cb6 Mon Sep 17 00:00:00 2001 From: Anand Date: Tue, 9 Aug 2022 18:47:55 +0530 Subject: [PATCH 07/13] Implemented Classe and objects --- IA2-18.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 IA2-18.py diff --git a/IA2-18.py b/IA2-18.py new file mode 100644 index 0000000..0ccd35c --- /dev/null +++ b/IA2-18.py @@ -0,0 +1,61 @@ +""" +We will use this script to learn Python:Concepts of _Class and Objects in BMI Calculator. +The script is an example of BMI_Calculator implemented in Python using methods and constructor. +The BMI_Calculator: + # Get the weight(Kg) of the user + # Get the height(m) of the user + # Caculate the BMI using the formula + BMI=weight in kg/height in meters*height in meters + + + """ +class BMI_Calculator: + pass + + #class variable + BMI = 'calculator' + + #The init constructor for weight & height + def __int__(self,weight,height): + + #instance variable + self.weight = weight + self.height = height + + + #another instance constructor for weight & height + def calculate_BMI(self): + return (round((self.weight/self.height)**2),2) + + +weight = float(input("Enter the weight in kg:")) +height = float(input("Enter the height in meters:")) + + #object instant +file = BMI_Calculator(weight, height) +print("The BMI of the user is: ", file.calculate_BMI(), "kg/sq.metre") +# inputs for the weight & height of the user + + +if BMI_Calculator< 18.5: + print("Oh No!!! UnderWeight") + print("The Ideal BMI Range is : 18.5 to 25 ") + Gain_Weight = round((18.5 * weight * height - weight), 2) + print("Weight to be Gained to Reach the Ideal BMI is:", Gain_Weight, "Kg") + +elif BMI_Calculator >= 18.5 and BMI_Calculator <= 25: + print("Hurrayyy!!! NormalWeight") + print("The Ideal BMI Range is : 18.5 to 25") + print("Good Keep It Up") + +elif BMI_Calculator > 25 and BMI_Calculator <= 29.99: + print("Ohhh!!! OverWeight") + print("The Ideal BMI Range is : 18.5 to 25") + Reduce_Weight = round((weight - height * height * 25), 2) + print("Weight to be Reduced to Reach the Ideal BMI is :", Reduce_Weight,"Kg") + +elif BMI_Calculator >= 30: + print("{face screaming in fear}") + print("The Ideal BMI Range is : 18.5 to 25") + Reduce_Weight = round((weight - height * height * 25), 2) + print("Weight to be Reduced to Reach the Ideal BMI is :{1}", Reduce_Weight, "Kg") \ No newline at end of file From bd7849b64cd2dfb2fdf4549809b8a91562126d56 Mon Sep 17 00:00:00 2001 From: Anand Roy <110399775+AnandRoy92@users.noreply.github.com> Date: Wed, 10 Aug 2022 15:38:29 +0530 Subject: [PATCH 08/13] Delete IA2-18.py --- IA2-18.py | 61 ------------------------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 IA2-18.py diff --git a/IA2-18.py b/IA2-18.py deleted file mode 100644 index 0ccd35c..0000000 --- a/IA2-18.py +++ /dev/null @@ -1,61 +0,0 @@ -""" -We will use this script to learn Python:Concepts of _Class and Objects in BMI Calculator. -The script is an example of BMI_Calculator implemented in Python using methods and constructor. -The BMI_Calculator: - # Get the weight(Kg) of the user - # Get the height(m) of the user - # Caculate the BMI using the formula - BMI=weight in kg/height in meters*height in meters - - - """ -class BMI_Calculator: - pass - - #class variable - BMI = 'calculator' - - #The init constructor for weight & height - def __int__(self,weight,height): - - #instance variable - self.weight = weight - self.height = height - - - #another instance constructor for weight & height - def calculate_BMI(self): - return (round((self.weight/self.height)**2),2) - - -weight = float(input("Enter the weight in kg:")) -height = float(input("Enter the height in meters:")) - - #object instant -file = BMI_Calculator(weight, height) -print("The BMI of the user is: ", file.calculate_BMI(), "kg/sq.metre") -# inputs for the weight & height of the user - - -if BMI_Calculator< 18.5: - print("Oh No!!! UnderWeight") - print("The Ideal BMI Range is : 18.5 to 25 ") - Gain_Weight = round((18.5 * weight * height - weight), 2) - print("Weight to be Gained to Reach the Ideal BMI is:", Gain_Weight, "Kg") - -elif BMI_Calculator >= 18.5 and BMI_Calculator <= 25: - print("Hurrayyy!!! NormalWeight") - print("The Ideal BMI Range is : 18.5 to 25") - print("Good Keep It Up") - -elif BMI_Calculator > 25 and BMI_Calculator <= 29.99: - print("Ohhh!!! OverWeight") - print("The Ideal BMI Range is : 18.5 to 25") - Reduce_Weight = round((weight - height * height * 25), 2) - print("Weight to be Reduced to Reach the Ideal BMI is :", Reduce_Weight,"Kg") - -elif BMI_Calculator >= 30: - print("{face screaming in fear}") - print("The Ideal BMI Range is : 18.5 to 25") - Reduce_Weight = round((weight - height * height * 25), 2) - print("Weight to be Reduced to Reach the Ideal BMI is :{1}", Reduce_Weight, "Kg") \ No newline at end of file From 8e9b567b3fc8546f5e81f01b66fc8d38ab069d1b Mon Sep 17 00:00:00 2001 From: Anand Date: Wed, 10 Aug 2022 15:54:44 +0530 Subject: [PATCH 09/13] Revert "Delete IA2-18.py" This reverts commit bd7849b64cd2dfb2fdf4549809b8a91562126d56. --- IA2-18.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 IA2-18.py diff --git a/IA2-18.py b/IA2-18.py new file mode 100644 index 0000000..0ccd35c --- /dev/null +++ b/IA2-18.py @@ -0,0 +1,61 @@ +""" +We will use this script to learn Python:Concepts of _Class and Objects in BMI Calculator. +The script is an example of BMI_Calculator implemented in Python using methods and constructor. +The BMI_Calculator: + # Get the weight(Kg) of the user + # Get the height(m) of the user + # Caculate the BMI using the formula + BMI=weight in kg/height in meters*height in meters + + + """ +class BMI_Calculator: + pass + + #class variable + BMI = 'calculator' + + #The init constructor for weight & height + def __int__(self,weight,height): + + #instance variable + self.weight = weight + self.height = height + + + #another instance constructor for weight & height + def calculate_BMI(self): + return (round((self.weight/self.height)**2),2) + + +weight = float(input("Enter the weight in kg:")) +height = float(input("Enter the height in meters:")) + + #object instant +file = BMI_Calculator(weight, height) +print("The BMI of the user is: ", file.calculate_BMI(), "kg/sq.metre") +# inputs for the weight & height of the user + + +if BMI_Calculator< 18.5: + print("Oh No!!! UnderWeight") + print("The Ideal BMI Range is : 18.5 to 25 ") + Gain_Weight = round((18.5 * weight * height - weight), 2) + print("Weight to be Gained to Reach the Ideal BMI is:", Gain_Weight, "Kg") + +elif BMI_Calculator >= 18.5 and BMI_Calculator <= 25: + print("Hurrayyy!!! NormalWeight") + print("The Ideal BMI Range is : 18.5 to 25") + print("Good Keep It Up") + +elif BMI_Calculator > 25 and BMI_Calculator <= 29.99: + print("Ohhh!!! OverWeight") + print("The Ideal BMI Range is : 18.5 to 25") + Reduce_Weight = round((weight - height * height * 25), 2) + print("Weight to be Reduced to Reach the Ideal BMI is :", Reduce_Weight,"Kg") + +elif BMI_Calculator >= 30: + print("{face screaming in fear}") + print("The Ideal BMI Range is : 18.5 to 25") + Reduce_Weight = round((weight - height * height * 25), 2) + print("Weight to be Reduced to Reach the Ideal BMI is :{1}", Reduce_Weight, "Kg") \ No newline at end of file From d3f3182707248ed247de92dcfe316f8fb5bfa44c Mon Sep 17 00:00:00 2001 From: Anand Date: Wed, 10 Aug 2022 16:48:59 +0530 Subject: [PATCH 10/13] Implemented class in BMI --- IA2-18.py => BMI_Calculator_01.py | 9 +++--- BMR/{BMR_01.py => BMR_Calculator_01.py} | 40 ++++++++++++------------- 2 files changed, 25 insertions(+), 24 deletions(-) rename IA2-18.py => BMI_Calculator_01.py (87%) rename BMR/{BMR_01.py => BMR_Calculator_01.py} (89%) diff --git a/IA2-18.py b/BMI_Calculator_01.py similarity index 87% rename from IA2-18.py rename to BMI_Calculator_01.py index 0ccd35c..cc442c8 100644 --- a/IA2-18.py +++ b/BMI_Calculator_01.py @@ -16,7 +16,7 @@ class BMI_Calculator: BMI = 'calculator' #The init constructor for weight & height - def __int__(self,weight,height): + def __init__(self,weight,height): #instance variable self.weight = weight @@ -25,17 +25,18 @@ def __int__(self,weight,height): #another instance constructor for weight & height def calculate_BMI(self): - return (round((self.weight/self.height)**2),2) + return round((self.weight/(self.height*self.height)),2) weight = float(input("Enter the weight in kg:")) height = float(input("Enter the height in meters:")) #object instant -file = BMI_Calculator(weight, height) -print("The BMI of the user is: ", file.calculate_BMI(), "kg/sq.metre") +BMI_file = BMI_Calculator(weight, height) +print("The BMI of the user is: ", BMI_file.calculate_BMI(), "kg/sq.metre") # inputs for the weight & height of the user +BMI_Calculator =BMI_file.calculate_BMI() if BMI_Calculator< 18.5: print("Oh No!!! UnderWeight") diff --git a/BMR/BMR_01.py b/BMR/BMR_Calculator_01.py similarity index 89% rename from BMR/BMR_01.py rename to BMR/BMR_Calculator_01.py index 7864d0a..c748a9f 100644 --- a/BMR/BMR_01.py +++ b/BMR/BMR_Calculator_01.py @@ -5,55 +5,58 @@ # 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 + # Get the height(m/foot-in") of the user + # 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 config file in helper.py. Then import the configure file i.e 'Config.ini' to main script i.e. BMR_Calculator_01 +Exercise 2: Calculate the BMR +Exercise 3: Calculate the Calorie intake with respect to BMR result multiply with constant, which solves the 'Exercise:3' +Exercise 4: 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. -""" -import configparser - - +Here User-defined functions are used along with calling function """ +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() 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/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:")) - - + 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 " + + #requirement.txt= Here Configparser() lib has been used. Refer to 'config.py' and helper.py file. config_BMR= configparser.ConfigParser() config_BMR.read("Config.ini") - x = config_BMR["Male"] constant_for_male = float(x["constant_for_male"]) weight_constant_for_male = float(x["weight_constant_for_male"]) @@ -69,7 +72,8 @@ def calculate_bmr (Weight_of_the_user, Height_of_the_user, Age_of_the_user,Units CV = config_BMR["Conversion"] pound = float(CV["pound"]) foot = float(CV["foot"]) - # Here if the Gender_of_the_user is 'M' i.e Male, then formula will be: + # 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 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 @@ -92,7 +96,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,14 +122,11 @@ 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("You should take more calorie intake: No Excecise (0 Day)!!") 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() From 98419d924f84d1b2b964e3d4e254a9c7d71fb366 Mon Sep 17 00:00:00 2001 From: Anand Date: Fri, 12 Aug 2022 09:19:31 +0530 Subject: [PATCH 11/13] Implemented class --- BMR/BMR_Cls.py | 115 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 BMR/BMR_Cls.py diff --git a/BMR/BMR_Cls.py b/BMR/BMR_Cls.py new file mode 100644 index 0000000..2d93d39 --- /dev/null +++ b/BMR/BMR_Cls.py @@ -0,0 +1,115 @@ +class Player(object): + # Class Attributes, tracking all players + players = {} + id_player_names = {} # Just something to help you track id to players + last_id = 0 + + def __init__(self, name=None, height=0, weight=0, bmi=0): + + # Player attributes, tracking a player's stats + self.name = name + self.height = height + self.weight = weight + self.bmi = bmi + + self.player_id = Player.last_id + 1 + + # Register the player + Player.register_player(self.player_id, name, height, weight, bmi) + + @classmethod + def register_player(cls, player_id, name, height, weight, bmi): + + cls.players.update({player_id: + {"name": name, "height": height, "weight": weight, "bmi": bmi} + + }) + cls.id_player_names.update({player_id: name}) + + cls.last_id = max(cls.id_player_names, key=int) + + @classmethod + def list_all_players(cls): + for player_id, name in cls.id_player_names.items(): + print("Player ID: ", player_id, "name: ", name) + return cls.id_player_names + + @classmethod + def list_all_players_stats(cls): + for player_id, stats in cls.players.items(): + print("Player ID: ", player_id, stats['name'], "\n", "stats: ", stats, "\n") + return cls.players + + @classmethod + def update_player(cls, player_id, **kwargs): + + cls.players[player_id].update(kwargs) + + if "name" in kwargs: + cls.id_player_names[player_id] = kwargs['name'] + + # print("player_id: ", player_id, "name: ", cls.id_player_names[player_id], "has been updated") + + @classmethod + def get_player_stats(cls, player_id): + return cls.players[player_id] + + def stats(self): + return Player.get_player_stats(self.player_id) + + def get_height(self): + height = float(input("Please enter player's height in metres: ")) + self.height = height + Player.update_player(self.player_id, height=height) + + return height + + def get_weight(self): + weight = float(input("Please enter player's weight in kg: ")) + self.weight = weight + + Player.update_player(self.player_id, weight=weight) + + return weight + + @staticmethod + def calculate_bmi(height, weight): + + bmi = round((weight / (height*height)), 1) + + return bmi + + def get_bmi(self): + if self.height is 0: + self.get_height() + if self.weight is 0: + self.get_weight() + + bmi = self.calculate_bmi(self.height, self.weight) + Player.update_player(self.player_id, bmi=bmi) + self.bmi = bmi + + return self.bmi + + +# Example use case +if __name__ == '__main__': + players_added = 0 + while True: + + if players_added == 5: + print("Total roster of players added \n") + print(Player.list_all_players()) + players_added = 0 + + name = input("What is the player's name?: ") + a_player = Player(name) + a_player.get_bmi() + + print("Displaying {}'s stats".format(name)) + print(a_player.stats(), "\n") + + print("Listing all player's stats") + Player.list_all_players_stats() + + players_added += 1 From 06a3b4dfadc44e06e9b873c3f4bf0079a44a5f56 Mon Sep 17 00:00:00 2001 From: Anand Roy <110399775+AnandRoy92@users.noreply.github.com> Date: Fri, 12 Aug 2022 09:20:26 +0530 Subject: [PATCH 12/13] Delete BMR_Calculator_01.py --- BMR/BMR_Calculator_01.py | 142 --------------------------------------- 1 file changed, 142 deletions(-) delete mode 100644 BMR/BMR_Calculator_01.py diff --git a/BMR/BMR_Calculator_01.py b/BMR/BMR_Calculator_01.py deleted file mode 100644 index c748a9f..0000000 --- a/BMR/BMR_Calculator_01.py +++ /dev/null @@ -1,142 +0,0 @@ -""" 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/foot-in") of the user - # 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:Create config file in helper.py. Then import the configure file i.e 'Config.ini' to main script i.e. BMR_Calculator_01 -Exercise 2: Calculate the BMR -Exercise 3: Calculate the Calorie intake with respect to BMR result multiply with constant, which solves the 'Exercise:3' -Exercise 4: 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. - -Here User-defined functions are used along with calling function """ - -import configparser -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() - 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/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:")) - 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 " - - #requirement.txt= Here Configparser() lib has been used. Refer to 'config.py' and helper.py file. - config_BMR= configparser.ConfigParser() - config_BMR.read("Config.ini") - - x = config_BMR["Male"] - 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"] - 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"]) - 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 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 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 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 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 - - -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. " - #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)!!") - 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 - else: - print("You should take more calorie intake: No Excecise (0 Day)!!") - -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 f174a9003d23155e44bc4328c47fbc7c3ed2a0f5 Mon Sep 17 00:00:00 2001 From: Anand Roy <110399775+AnandRoy92@users.noreply.github.com> Date: Fri, 12 Aug 2022 09:22:02 +0530 Subject: [PATCH 13/13] Delete BMR_Cls.py --- BMR/BMR_Cls.py | 115 ------------------------------------------------- 1 file changed, 115 deletions(-) delete mode 100644 BMR/BMR_Cls.py diff --git a/BMR/BMR_Cls.py b/BMR/BMR_Cls.py deleted file mode 100644 index 2d93d39..0000000 --- a/BMR/BMR_Cls.py +++ /dev/null @@ -1,115 +0,0 @@ -class Player(object): - # Class Attributes, tracking all players - players = {} - id_player_names = {} # Just something to help you track id to players - last_id = 0 - - def __init__(self, name=None, height=0, weight=0, bmi=0): - - # Player attributes, tracking a player's stats - self.name = name - self.height = height - self.weight = weight - self.bmi = bmi - - self.player_id = Player.last_id + 1 - - # Register the player - Player.register_player(self.player_id, name, height, weight, bmi) - - @classmethod - def register_player(cls, player_id, name, height, weight, bmi): - - cls.players.update({player_id: - {"name": name, "height": height, "weight": weight, "bmi": bmi} - - }) - cls.id_player_names.update({player_id: name}) - - cls.last_id = max(cls.id_player_names, key=int) - - @classmethod - def list_all_players(cls): - for player_id, name in cls.id_player_names.items(): - print("Player ID: ", player_id, "name: ", name) - return cls.id_player_names - - @classmethod - def list_all_players_stats(cls): - for player_id, stats in cls.players.items(): - print("Player ID: ", player_id, stats['name'], "\n", "stats: ", stats, "\n") - return cls.players - - @classmethod - def update_player(cls, player_id, **kwargs): - - cls.players[player_id].update(kwargs) - - if "name" in kwargs: - cls.id_player_names[player_id] = kwargs['name'] - - # print("player_id: ", player_id, "name: ", cls.id_player_names[player_id], "has been updated") - - @classmethod - def get_player_stats(cls, player_id): - return cls.players[player_id] - - def stats(self): - return Player.get_player_stats(self.player_id) - - def get_height(self): - height = float(input("Please enter player's height in metres: ")) - self.height = height - Player.update_player(self.player_id, height=height) - - return height - - def get_weight(self): - weight = float(input("Please enter player's weight in kg: ")) - self.weight = weight - - Player.update_player(self.player_id, weight=weight) - - return weight - - @staticmethod - def calculate_bmi(height, weight): - - bmi = round((weight / (height*height)), 1) - - return bmi - - def get_bmi(self): - if self.height is 0: - self.get_height() - if self.weight is 0: - self.get_weight() - - bmi = self.calculate_bmi(self.height, self.weight) - Player.update_player(self.player_id, bmi=bmi) - self.bmi = bmi - - return self.bmi - - -# Example use case -if __name__ == '__main__': - players_added = 0 - while True: - - if players_added == 5: - print("Total roster of players added \n") - print(Player.list_all_players()) - players_added = 0 - - name = input("What is the player's name?: ") - a_player = Player(name) - a_player.get_bmi() - - print("Displaying {}'s stats".format(name)) - print(a_player.stats(), "\n") - - print("Listing all player's stats") - Player.list_all_players_stats() - - players_added += 1