Python で関数を作成するのに問題があります。ユーザーがリストに単語を入力できるようにし、追加の単語を入力するかどうかをユーザーに尋ねる機能が欲しいです。ユーザーが「n」を入力した場合、関数がリストに入力された単語を返すようにしたいと思います。関数を実行すると、追加の単語を 2 回入力するかどうかをユーザーに尋ねます。また、リストは返されません。
def add_list(x):
first_list = raw_input('Please input a word to add to a list ')
x.append(first_list)
response = None
while response != 'n':
response = raw_input('Would you like to enter another word? ')
if response == 'n':
print 'Here is the list of words'
return x
else:
add_list(x)
def main():
add_list(x)
x = []
main()