0

I'm new to functions and cannot figure out why this returns 'None' Essentially the State is a number, so this should input the state and spit out the population. I'll change the format to be more vague and helpful for all once I understand better. Thanks!

def ca_pov(state, spending=0):
 state = person[person.state==state].copy(deep=True)
 total_population = state.weight.sum()
 return
 total_population
print(ca_pov(11))
asked Jul 12, 2020 at 13:53
3
  • 2
    you need returnvalue on the same line :) Commented Jul 12, 2020 at 13:54
  • 2
    Also you can inline it return person[person.state==state].copy(deep=True).weight.sum() Commented Jul 12, 2020 at 13:54
  • 1
    I'll chip in with some explanation as to why you were getting None. When you use the return call, you have to specify what you want to be returned on the same line as return. In your example, you had return and then your desired outcome was specified in a new line. This made Python think that you did not want anything to be returned, hence None. Hope it helps. Commented Jul 12, 2020 at 13:56

1 Answer 1

2

the total_population was not returned. You have to write the return keyword and the data you want to return next to it.

def ca_pov(state, spending=0):
 state = person[person.state==state].copy(deep=True)
 total_population = state.weight.sum()
 return total_population
print(ca_pov(11))
answered Jul 12, 2020 at 13:53
Sign up to request clarification or add additional context in comments.

1 Comment

@Nate Go if this works for you please accept my question and upvote it :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.