I’m struggling with the US American Insurance. I’ve some ideas of what I want to analyze. I was trying to find out the avg cost of the insurance by sex. I’ve two paths and I want to test both of them. One is with dict and the other without.
Here I was working with the without and when I ran the code, it says I don’t have the female_count or male_count define. What I’m missing?
It looks like you have the wrong arguments for the
cost_per_sexes function on the last line.
There should be something you can use for
The weird part is that it says that male_count is not defined, and I did it inside the formula.
That’s a scope issue.
variables defined/declared inside a function would not be accessible outside the function,
and that last line is outside the function. (That’s outside the scope of the variable.)
But if I moved the “return” inside, I will have the same issue. Sorry, I’m not following how I can solved this.
I’d try something more like
costs = cost_per_sexes(listOfSexes, listOfCharges)
print("There are " + str(costs) + " females, with a total cost of " + str(round(costs, 2)) + " dollars.")
possibly with the appropriate lists for
listOfCharges if (those variables are named something else before the function).
Notice that the function returns a
female_count was at index 0 in the tuple, and
female_cost was at index 3 in the tuple.