Why does my recursive function return None?
It is returning None
because when you recursively call it:
if my_var != "a" and my_var != "b": print('You didn\'t type "a" or "b". Try again.') get_input()
..you don't return the value.
So while the recursion does happen, the return value gets discarded, and then you fall off the end of the function. Falling off the end of the function means that python implicitly returns None
, just like this:
>>> def f(x):... pass>>> print(f(20))None
So, instead of just calling get_input()
in your if
statement, you need to return
it:
if my_var != "a" and my_var != "b": print('You didn\'t type "a" or "b". Try again.') return get_input()