私は自分自身を呼び出すこの関数を持っています:
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())
ここで、「a」または「b」だけを入力すると、すべて正常に動作します。
Type "a" or "b": a
got input: a
しかし、何か他のものを入力してから「a」または「b」を入力すると、次のようになります。
Type "a" or "b": purple
You didn't type "a" or "b". Try again.
Type "a" or "b": a
got input: None
のみが返されるはずなので、なぜget_input()
返されるのかわかりません。これはどこから来て、どうすれば機能を修正できますか?None
my_var
None