-3

Hello I am currently having trouble with one of my current homework assignments for python. I'm in the process of making a calorie counter and following along with my instructors videos he made and provided for us. I have all my code complete and done for this lesson but I keep getting an error code I have never received before. the error I keep receiving is

[code] File "E:\CC PART LESSON 811.py", line 129, in <module>
    tot_cals, item_cnt = add_process(tot_cals, item_cnt)
  File "E:\CC PART LESSON 811.py", line 93, in add_process
    cals = calc_cals("c", g_carbs) + calc_cals("f", g_fats) + calc_cals("p", g_prot)
TypeError: 'int' object is not callable [code]

My code lets users pick whether they want to add food to their list or to end the program, and when they do add things, my code uses a function to add that item to their list, so they are prompted to input the carbs fats and protein of said item. When I finish entering in the inputs, my program crashes and it gives me the error above. I have tried googling this error and can only find solutions pertaining to specific code. What am I doing wrong and how can I go about fixing it? I have looked over my whole program multiple times and compared it with my instructors videos and can't seem to find what I did wrong! Thanks a ton!

The function and the code for it is:

while True:
    choice = disp_menu()
    if choice == "a":
        tot_cals, item_cnt = add_process(tot_cals, item_cnt)

def add_process(tot_cals, item_cnt):
    item_name = input_name()
    g_carbs = input_grams("carbs")
    g_fats = input_grams("fats")
    g_prot = input_grams("protein")


    cals = calc_cals("c", g_carbs) + calc_cals("f", g_fats) + calc_cals("p", g_prot)

my variables are as listed:

tot_cals = 0
item_list = 0
item_cnt = 0
calc_cals = 0

and sorry for the bad formatting; I am still learning how to code and use coding forums. Thanks so much guys! And also, is this enough of my code? I believe the error is coming from these two parts but I am not 100%. Thanks!

Austin7887
  • 11
  • 1
  • You should share the code that generates the error. – FiReTiTi Mar 05 '16 at 09:35
  • 1
    My guess is that you have re-used the name of one of your functions for a simple integer variable. But we need to see code in order to debug it. Preferably do _not_ post the whole thing: try to construct a [mcve] that demonstrates your problem. – PM 2Ring Mar 05 '16 at 09:36
  • @Austin7887 please post the code in the question itself, not the comment section. Also, select you code & do a Ctrl+k to format it. – Alok Mar 05 '16 at 10:00

1 Answers1

2

The reason you get that error is because you are using calc_cals both as a variable and a function:

Your call stack shows a function call to calc_cals

File "E:\CC PART LESSON 811.py", line 93, in add_process
     cals = calc_cals("c", g_carbs) + calc_cals("f", g_fats) + calc_cals("p", g_prot)

While you state that your variables include:

calc_cals = 0
Juan Leni
  • 6,982
  • 5
  • 55
  • 87