import sys import math """ To use, just run python macronutrientcalc.py """ 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)))