Debugging functions

I am on debugging functions on part 12. I am gettting a :slight_smile:

  • avg_rating isn’t defined in your code, but we expected it to be float type
  • avg_price isn’t defined in your code, but we expected it to be float type

even when I put in the solution answer it still is not correct.

below is the code:
def mean(data_set, index):
column = extract(data_set, index)
return find_sum(column) / find_length(column)

avg_price = mean(apps_data, 4)
avg_rating = mean(apps_data, 7)


TypeErrorTraceback (most recent call last)
in ()
34
35
—> 36 print(avg_rating)

TypeError: ‘float’ object is not callable

Hi @hostonmel, welcome to the community!

When going through the process of debugging code, sometimes errors occur because of a bug earlier on. The mean() function defined here depends on 3 other functions. It’s possible that one (or more?) of the other functions contains some kind of error so that avg_rating can’t be executed properly.

Here is what I do when I’m trying to find the source of the problem. I test each of the functions separately and see if the output I get is what I expected. To test, comment out the last 2 lines that use all the functions to find the mean. Then you can add lines that use just one of the functions at a time, starting with the extract() function:

column = extract(apps_data, 7)

If you get the value you expect for column (a list of numbers), then you can add these lines to test the find_sum() and find_length() functions:

test1 = find_length(column)
test2 = find_sum(column)

If you get weird results when you inspect the variables, then you know more specifically where to look for an error.

If that doesn’t help, post here again with all of the code so other members of the community can have a look and help you figure it out. When you copy your code, make sure to put three backticks before the code you copied and 3 backticks after the code so that Markdown can format it correctly with all the lovely indents. (See this post if you don’t know what I mean.)