1. def main():
  2.  
  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. #------add food-------------------
  17.  
  18. while True:
  19. diet_plan = raw_input("Would you like to add foods into your diet?(y/n): ")
  20. if diet_plan == 'y':
  21. item_name = raw_input("What is the name of the food you would like to add? ")
  22. size_serv = input("What is the size(grams) in each serving of %s? " % item_name)
  23. calorie_serv = input("How many calories is in each serving of %s? " % item_name)
  24. protein_serv = input("How many grams of protein is in each serving of %s? " % item_name)
  25. carb_serv = input("How many grams of carbohydrates is in each serving of %s? " % item_name)
  26. fat_serv = input("How many grams of fat is in each serving of %s? " % item_name)
  27. num_serv = input("How many servings of %s would you like to add? " % item_name)
  28.  
  29. # diet_foodlist = add_food_item()
  30. # diet_foodlist.food_database(item_name, size_serv, calorie_serv, protein_serv, carb_serv, fat_serv)
  31. # diet_foodlist.food_in_diet(item_name, size_serv, calorie_serv, protein_serv, carb_serv, fat_serv, num_serv)
  32. food_database(item_name, size_serv, calorie_serv, protein_serv, carb_serv, fat_serv)
  33. food_in_diet(item_name, size_serv, calorie_serv, protein_serv, carb_serv, fat_serv, num_serv)
  34.  
  35. add_food()
  36. break
  37.  
  38. if diet_plan == 'n':
  39. break
  40. answer = raw_input("Are you done using the calculator?(y/n): ")
  41. if not ask_to_leave(answer):
  42. break
  43. else:
  44. continue
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. def Total_Macro_Check(total_val):
  53. if total_val > 100:
  54. print "Total percentages surpassed 100! Please reenter percentages."
  55. return False
  56. if total_val < 100:
  57. print "Total precentages is less than 100! Please reenter precentages."
  58. return False
  59. return True
  60.  
  61. def Macro_percentage_to_calorie(calorie, protein, carb, fat):
  62. """ calories in 1 gram of P/C/F """
  63. cal_in_protein = 4
  64. cal_in_fat = 9
  65. cal_in_carb = 4
  66.  
  67. """ multiple percentages with calories """
  68. mult_protein = protein/100.0
  69. mult_fat = fat/100.0
  70. mult_carb = carb/100.0
  71.  
  72. calories_of_protein = calorie*mult_protein
  73. grams_of_protein = calories_of_protein/cal_in_protein
  74. print "You must eat " + str(calories_of_protein) + " calories of protein which is equivalent to " + str(grams_of_protein) + " grams of protein."
  75.  
  76. calories_of_fat = calorie*mult_fat
  77. grams_of_fat = calories_of_fat/cal_in_fat
  78. print "You must eat " + str(calories_of_fat) + " calories of fat which is equivalent to " + str(grams_of_fat) + " grams of fat."
  79.  
  80. calories_of_carb = calorie*mult_carb
  81. grams_of_carb = calories_of_carb/cal_in_fat
  82. print "You must eat " + str(calories_of_carb) + " calories of carbohydrates which is equivalent to " + str(grams_of_carb) + " grams of carbohydrates."
  83.  
  84. def ask_to_leave(value):
  85. if value == 'y':
  86. return False
  87. elif value == 'n':
  88. return True
  89.  
  90.  
  91.  
  92. def food_database(item_name, size_serv, calorie_serv, protein_serv, carb_serv, fat_serv):
  93. # used to list the different foods when users ask for it
  94. # food database
  95. food_dict = [ {
  96. 'food_name': item_name,
  97. 'serving_size': size_serv,
  98. 'serving_calorie': calorie_serv,
  99. 'serving_protien': protein_serv,
  100. 'serving_fat': fat_serv,
  101. 'serving_carb': carb_serv
  102. } ]
  103. print food_dict
  104.  
  105. def food_in_diet(item_name, size_serv, calorie_serv, protein_serv, carb_serv, fat_serv, num_serv):
  106. # used to show how much is in the diet plan for the user
  107. User_diet_dict = [ {
  108. 'food_name': item_name,
  109. 'amount': num_serv*size_serv,
  110. 'serving_calorie': num_serv*calorie_serv,
  111. 'serving_protien': protein_serv,
  112. 'serving_fat': fat_serv,
  113. 'serving_carb': carb_serv
  114. } ]
  115. print User_diet_dict
  116.  
  117.  
  118. #---------------------------------------------------------------------------------------------------------------
  119.  
  120. def add_food():
  121. ask_to_add_another = raw_input("Would you like to add another food?(y/n)")
  122. if ask_to_add_another == 'y':
  123. # update
  124. item_name = raw_input("What is the name of the food you would like to add? ")
  125. size_serv = input("What is the size(grams) in each serving of %s? " % item_name)
  126. calorie_serv = input("How many calories is in each serving of %s? " % item_name)
  127. protein_serv = input("How many grams of protein is in each serving of %s? " % item_name)
  128. carb_serv = input("How many grams of carbohydrates is in each serving of %s? " % item_name)
  129. fat_serv = input("How many grams of fat is in each serving of %s? " % item_name)
  130. num_serv = input("How many servings of %s would you like to add? " % item_name)
  131.  
  132. food_dict.append( {
  133. 'food_name': 'item_name',
  134. 'serving_size': size_serv,
  135. 'serving_calorie': calorie_serv,
  136. 'serving_protien': protein_serv,
  137. 'serving_fat': fat_erv,
  138. 'serving_carb': carb_serv
  139. } )
  140.  
  141. # User_diet_dict.append = ( {
  142. # 'food_name': item_name,
  143. # 'amount': num_serv*size_serv,
  144. # 'serving_calorie': num_serv*calorie_serv,
  145. # 'serving_protien': protein_serv,
  146. # 'serving_fat': fat_serv,
  147. # 'serving_carb': carb_serv
  148. # } )
  149. # add to the dictonary/list
  150. print food_dict
  151. add_food()
  152. if ask_to_add_another == 'n':
  153. return False
  154.  
  155.  
  156.  
  157. if __name__ == "__main__":
  158. main()