In this tutorial, we will create a python program that calculates the amount of calories you need to take during the diet.
A calorie is a unit of energy. In nutrition, calories refer to the energy people get from the food and drink they consume, and the energy they use in physical activity.
Python Code:
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 |
CALORIES_PER_POUND = 3500 def main(): try: current_weight = float(input('please enter your current weight in pounds: ')) target_weight = float(input('please enter your target weight in pounds: ')) NumDays = int(input('please enter the number of days you have been on the diet: ')) calories_burned = float(input('please enter the number of calories you burn per day: ')) except ValueError as err: print ('Please enter a numeric value') return calc_weight(current_weight, target_weight, NumDays, calories_burned) def calc_weight(v, w, x, y): days_required = (v - w) * CALORIES_PER_POUND / y months_required = (days_required / 30) remaining_days = (days_required - x) remaining_months = (remaining_days / 30) pounds_remaining = ((v - w) - (y * x) / CALORIES_PER_POUND) pounds_burned = ((v - w) - pounds_remaining) print ('days required: ', days_required, 'months required: ', months_required, 'remaining days: ', remaining_days) print ('months remaining: ', remaining_months, 'pounds burned: ', pounds_burned, 'pounds remaining: ', pounds_remaining) main() |
Output:

Add comment