Guest User

Untitled

a guest
May 31st, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1.  
  2. def main():
  3. while True:
  4. print "*******Welcome to the MACRONUTRIENT CALCULATOR********"
  5. calorie_deficit = float(input("Enter your calorie deficit: "))
  6. Percent_protein = float(input("Percentage of Protein: "))
  7. Percent_carb = float(input("Percent of Carbohydrates: "))
  8. Percent_fat = float(input("Percentage of Fats: "))
  9. Macro_dict = {'Protein': Percent_protein, 'Carbohydrate': Percent_carb, 'Fats': Percent_fat}
  10. Macro_sum = Percent_protein + Percent_carb + Percent_fat
  11.  
  12. if not Total_Macro_Check(Macro_sum):
  13. continue
  14. Macro_percentage_to_calorie(calorie_deficit, Percent_protein, Percent_carb, Percent_fat)
  15.  
  16. while True:
  17. answer = str(input("Are you done using the calculator?(y/n): "))
  18. if not ask_to_leave(answer):
  19. break
  20. else:
  21. continue
  22.  
  23. def Total_Macro_Check(total_val):
  24. if total_val > 100:
  25. print "Total percentages surpassed 100! Please reenter percentages."
  26. return False
  27. if total_val < 100:
  28. print "Total precentages is less than 100! Please reenter precentages."
  29. return False
  30. return True
  31.  
  32. def Macro_percentage_to_calorie(calorie, protein, carb, fat):
  33. """ calories in 1 gram of P/C/F """
  34. cal_in_protein = 4
  35. cal_in_fat = 9
  36. cal_in_carb = 4
  37.  
  38. """ multiple percentages with calories """
  39. mult_protein = protein/100.0
  40. mult_fat = fat/100.0
  41. mult_carb = carb/100.0
  42.  
  43. calories_of_protein = calorie*mult_protein
  44. grams_of_protein = calories_of_protein/cal_in_protein
  45. print "You must eat " + str(calories_of_protein) + " calories of protein which is equivalent to " + str(grams_of_protein) + " grams of protein."
  46.  
  47. calories_of_fat = calorie*mult_fat
  48. grams_of_fat = calories_of_fat/cal_in_fat
  49. print "You must eat " + str(calories_of_fat) + " calories of fat which is equivalent to " + str(grams_of_fat) + " grams of fat."
  50.  
  51. calories_of_carb = calorie*mult_carb
  52. grams_of_carb = calories_of_carb/cal_in_fat
  53. print "You must eat " + str(calories_of_carb) + " calories of carbohydrates which is equivalent to " + str(grams_of_carb) + " grams of carbohydrates."
  54.  
  55. def ask_to_leave():
  56. if answer == 'y':
  57. return False
  58. elif answer == 'n':
  59. return True
  60.  
  61. if __name__ == "__main__":
  62. main()
Advertisement
Add Comment
Please, Sign In to add comment