-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparametersfunction.py
More file actions
53 lines (51 loc) · 2.27 KB
/
parametersfunction.py
File metadata and controls
53 lines (51 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def needed_calories(weight, height, age, gender, activity, unit): # Function to calculate the needed calories and protein intake
# setting all the variables to function required data types
weight = float(weight)
try:
height = float(height)
except:
height = height.split("'")
height = float(height[0]) * 12 + float(height[1])
age = int(age)
calories = 0
protein = 0
gender = gender.lower()
activity = activity.lower()
unit = unit.lower()
#calculatint the calories
if unit == 'metric': # checking if it is metric or imperial
if gender == "male": # checking gender
calories = (10 * weight) + (6.25 * height) - (5 * age) + 5 # calculating calories
elif gender == "female":
calories = (10 * weight) + (6.25 * height) - (5 * age) - 161
elif unit == 'imperial':
weight = weight * 0.453592 # converting weight to kg
height = height * 2.54 # converting height to cm
if gender == "male": # checking gender
calories = (10 * weight) + (6.25 * height) - (5 * age) + 5 # calculating calories
elif gender == "female":
calories = (10 * weight) + (6.25 * height) - (5 * age) - 161
# calculating the calories based on activity level
if activity == 'sedentary':
calories = calories * 1.2
elif activity == 'lightly active':
calories = calories * 1.375
elif activity == 'moderately active':
calories = calories * 1.55
elif activity == 'very active':
calories = calories * 1.725
elif activity == 'super active':
calories = calories * 1.9
# calculating the protein intake
if activity == 'sedentary' or activity == "lightly active":
protein = weight * 0.8
elif activity == 'moderately active':
protein = weight * 1.2
elif activity == 'very active' or activity == 'super active':
protein = weight * 1.8
# returning the calories and protein intake calories first protein second
calories = round(calories, 0)
protein = round(protein, 0)
return int(calories), int(protein)
if __name__ == "__main__": ## This is for testing purposes
print(needed_calories(200, "6'7", 19, "male", "sedentary", "imperial"))