-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclr_calculator.py
114 lines (85 loc) · 3.58 KB
/
clr_calculator.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
def main():
welcome()
gender = sex()
weight = get_weight()
height = get_height()
age = get_age()
rest_bmr = calculate_bmr(gender, weight, height, age)
total_calculation(rest_bmr)
def welcome():
print("Welcome to your calories python calculator!\nFind out How many calories should you eat daily.\n")
def sex():
sexes = ["male","female","M","F","f","m","Male","Female"]
while True:
sex = str(input("Do you identify as male or female? "))
while sex not in sexes:
sex = str(input("Please enter either 'male' or 'female' "))
else:
return sex
break
def get_weight():
weight_kg = float(input("Enter your weight in kilograms: "))
while weight_kg <= 0:
weight_kg = float(input("Invalid input. Please enter your weight in kilograms: "))
else:
return weight_kg
def get_height():
height_cm = float(input("Enter your height in Centimeters: "))
while height_cm <= 0:
height_cm = float(input("Invalid input. Please enter your height in Centimeters: "))
else:
return height_cm
def get_age():
age_yrs = int(input("Enter your age in years: "))
while age_yrs <= 0:
age_yrs = int(input("Invalid Input. Please enter your age in years: "))
else:
return age_yrs
def calculate_bmr(gender, weight, height, age):
male = ["male", "M" , "m", "Male"]
female = ["female", "F", "f", "Female"]
if gender == female:
women = (weight * 10) + (height * 6.25) - (age * 5) - 161
return int(women)
else:
men = (weight * 10) + (height * 6.25) - (age * 5) + 5
return int(men)
def total_calculation(rest_bmr):
user_activity_lvl = get_user_activity()
maintain = {
"sedentary" : get_sedentary(rest_bmr),
"light" : get_light_activity(rest_bmr),
"moderate" : get_moderate_activity(rest_bmr),
"active" : get_very_active(rest_bmr)
}
if user_activity_lvl == "sedentary":
print("You need to eat " + str(maintain["sedentary"]) + " calories a day to maintain your current weight")
if user_activity_lvl == "light":
print("You need to eat " + str(maintain["light"]) + " calories a day to maintain your current weight")
if user_activity_lvl == "moderate":
print("You need to eat " + str(maintain["moderate"]) + " calories a day to maintain your current weight")
if user_activity_lvl == "active":
print("You need to eat " + str(maintain["active"]) + " calories a day to maintain your current weight")
def get_user_activity():
activity_lvl = ["sedentary", "light", "moderate", "active"]
while True:
user_lvl = str(input("\nWhat is your activity level?\n\nSedentary is little to no exercise.\nLightly active is light exercise/sports 1 - 3 days/week.\nModerately active is moderate exercise/sports 3 - 5 days/week.\nVery active is hard exercise every day, or 2 xs/day 6 - 7 days/week.\n\nPlease enter: 'sedentary', 'light', 'moderate', or 'active' "))
while user_lvl not in activity_lvl:
user_lvl = str(input( "Invalid input. Please enter: 'sedentary', 'light', 'moderate', or 'active' "))
else:
return user_lvl
break
def get_sedentary(rest_bmr):
sedentary = rest_bmr * 1.25
return sedentary
def get_light_activity(rest_bmr):
light = rest_bmr * 1.375
return light
def get_moderate_activity(rest_bmr):
moderate = rest_bmr * 1.550
return moderate
def get_very_active(rest_bmr):
active = rest_bmr * 1.725
return active
if __name__ == '__main__':
main()