I'm new to python so I'm trying to practice by making a simple macro-nutrient calculator. I'm not quite sure how to pass certain values to different functions.
Here is my code
def Macro_input():
Percent_protein = input("Percentage of Protein: ")
float(Percent_protein)
Percent_carb = input("Percentage of Carbohydrates: ")
float(Percent_carb)
Percent_fat = input("Percentage of Fats: ")
float(Percent_fat)
Macro_dict = {'Protein': Percent_protein, 'Carbohydrate': Percent_carb, 'Fats': Percent_fat}
Macro_sum = Percent_protein + Percent_carb + Percent_fat
return Macro_sum
def Total_macro_check(Macro_sum):
#perhaps put all input into a dictionary? Macro['Protein':num, 'Carb':num, 'Fat':num]
if Macro_sum == 100:
print "You macronutrients percentages are \n Protein: "#, Macro_dict['Protein'], "%" #list for P/C/F --> %d
elif Macro_sum < 100:
print "Total percentages do not add up to 100. Please reenter percentages."
#go back to function that asks for Macros
elif Macro_sum > 100:
print "Total percentages surpass 100. Please reenter percentages."
#go back to function that asks for Macros
def main():
print "Please enter your macro-nutrients"
Total_macro_value = Macro_input()
Total_macro_check(Total_macro_value)
if __name__ == "__main__":
main()
What I want to do is output a Dictionary (Macro_dict),
So I can print it out if the sum of all macros (Macro_sum) is 100.
But I also want to check if Macro_sum equals 100.
This means I have to output a value Macro_sum into the function Total_macro_check.
However I feel as though if my Macro_input function returned Macro_sum and Macro_dict,
I cannot use its output in Total_macro_check due to it returning more than one value, while Total_macro_check only accepts 1 value.