Why do I keep getting the output I want and an unwanted "none"

Question:

def car(wheels,bodies,figures):
  car_by_wheels=wheels//4
  car_by_figures=figures/2
  if figures//2 >= car_by_wheels and bodies >= car_by_wheels:
    print(car_by_wheels)
  elif car_by_wheels >= car_by_figures and bodies >= car_by_figures:
    print(car_by_figures)
  elif car_by_wheels >= bodies and car_by_figures >= bodies:
    print(bodies)
  else:
    print("0")

print(car(3,29,54))

I tried a few other examples and the code works fine but I keep getting None. Why?

Asked By: AleeSarion

||

Answers:

Your function doesn’t explicitly return anything, so it implicitly returns None. So car(3,29,54) does it’s printing and returns None, which you then print.

Answered By: Tyberius
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.