-1
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?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • I noticed a coding error....probably caused when I tried to change "/" to "//"...more of a typo really. Anyway, I fixed that and I still have the issue. – AleeSarion Oct 25 '20 at 01:00
  • Does this answer your question? [What is the formal difference between "print" and "return"?](https://stackoverflow.com/questions/7664779/what-is-the-formal-difference-between-print-and-return) – OneCricketeer Oct 25 '20 at 01:15
  • Does this answer your question? [Python: My function returns "None" after it does what I want it to](https://stackoverflow.com/questions/19105961/python-my-function-returns-none-after-it-does-what-i-want-it-to) – DYZ Oct 25 '20 at 01:28
  • you need to `return` the value if you want to print outside the function, or you should simply run your function `car(3,29,54)` in last line instead of print(). – adamkwm Oct 25 '20 at 01:58

1 Answers1

0

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.

Tyberius
  • 625
  • 2
  • 12
  • 20