J'ai cette fonction qui s'appelle elle-même :
def get_input():
my_var = input('Enter "a" or "b": ')
if my_var != "a" and my_var != "b":
print('You didn\'t type "a" or "b". Try again.')
get_input()
else:
return my_var
print('got input:', get_input())
Maintenant, si je saisis juste "a" ou "b", tout fonctionne bien :
Type "a" or "b": a
got input: a
Mais si je tape autre chose et ensuite "a" ou "b", j'obtiens ceci :
Type "a" or "b": purple
You didn't type "a" or "b". Try again.
Type "a" or "b": a
got input: None
Je ne sais pas pourquoi. get_input()
est de retour None
puisqu'il ne devrait retourner que my_var
. Où se trouve cette None
et comment puis-je réparer ma fonction ?