Https://www.codecademy.com/courses/learn-python-3/projects/sals-shipping

For some reason, when printing out the code, I am getting a “None” in addition to my answer, and I don’t know from where the “None” is coming from. So my question is why am I getting “None” with my answer?

https://www.codecademy.com/courses/learn-python-3/projects/sals-shipping

Hi!

Welcome to the forums! It’s possible to get None in many different ways. You’d have to specifically show us the code that’s generating this response.

You can format the code by pressing the </> and pasting it withing the marked area.

2 Likes

Hello! As @toastedpitabread said, None can appear in many ways. One common mistake is to print a function call, when there is no return inside the function:

def a_function():
  print("Hello!")
print(a_function())

This will print:

>>Hello!
>>None

This happens because, since the function does not explicitly return anything (there is no return inside the function), it automatically ‘returns’ None. So when you print that result, the function is called, so the print statement is executed, but you are also printing the return value of the function, which is None.

I hope this helps!

2 Likes

Hi, sorry for the late reply but for some reason I just received it. https://gist.github.com/eec3c04a98bc2c20ad313996651f109b. This is the link to the code and although your answers were helpful, I don’t think they apply to my situation.

1 Like

@codeneutrino was right on the money (returning a function call without a return inside).

Review the last line of the cheapest_method() function:

def cheapest_method(weight):
    #function code
    #function code
    print("the cheapest option available is " + str(cost) + " with " + method)

print(cheapest_method(4.8))

A reminder of @codeneutrino’s example:

def a_function():
  print("Hello!")
print(a_function())

This will print:

Hello!
None
def a_function():
   return "Hello!"
print(a_function())

This will print:

Hello!
2 Likes