Skip to content

Instantly share code, notes, and snippets.

@damilare
Last active January 23, 2017 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damilare/f44013583892bbca9e4eb9340223ec44 to your computer and use it in GitHub Desktop.
Save damilare/f44013583892bbca9e4eb9340223ec44 to your computer and use it in GitHub Desktop.
Calculate your recommended calorie intake, and macronutrient ratio based on your weight and your level of activity
import sys
import math
"""
To use, just run python macronutrientcalc.py <body weight in kg> <lifestyle between 10 and 20>
"""
def _(num, numbers):
return math.floor((num / numbers) * 100)
try:
body_weight = int(sys.argv[1]) * 2.2 # convert kg to pounds
except IndexError:
body_weight = 180 # default in weignt in pounds
except ValueError:
print("Please supply numbers")
sys.exit()
try:
calories_needed = body_weight * int(sys.argv[2]) # level of activity
except IndexError:
calories_needed = body_weight * 12
except ValueError:
print("Please supply numbers")
protein = body_weight * 1.2
fat = body_weight * 0.5
protein_fat_calories = (protein * 4) + (fat * 9)
carbs = (calories_needed - protein_fat_calories) / 4
total_grams = sum([protein, fat, carbs])
print("Total Calorie Intake: %d" % ((carbs * 4) + protein_fat_calories))
print("{protein}g protein, {fat}g fat, {carbs}g carb,".format(protein=protein, fat=fat, carbs=carbs))
print("{protein}% protein, {fat}% fat, {carbs}% carb,".format(protein=_(protein, total_grams),
fat=_(fat, total_grams),
carbs=_(carbs, total_grams)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment