问题是只输入了一个单词并且对其调用了排序方法。让我们获取多个单词,将它们附加到列表中并对它们进行排序:input_words = []# Get input wordsword = input('Please enter word\n')# As long as word is not "stop"while word != 'stop': # Get new input word input_words.append(word) # Append to list of words word = input('Please enter word\n')# Sort wordsinput_words.sort()# Print sorted list of wordsprint(input_words)# Write to filewith open('your_file.txt', 'w') as f: for item in input_words: f.write("%s\n" % item)