def get_words():
words = []
while True:
word = raw_input('Please enter a word (or Enter to quit): ').strip().title()
if word:
words.append(word)
else:
return words
def main():
words = get_words()
print ("The words you entered, in alphabetical order, are:")
for i,word in enumerate(sorted(words), 1):
print('#{:>2d} {:.>16}'.format(i, ' '+word))
if __name__=="__main__":
main()
which results in
Please enter a word (or Enter to quit): giraffe
Please enter a word (or Enter to quit): tiger
Please enter a word (or Enter to quit): llama
Please enter a word (or Enter to quit): gnu
Please enter a word (or Enter to quit): albatross
Please enter a word (or Enter to quit):
The words you entered, in alphabetical order, are:
# 1 ...... Albatross
# 2 ........ Giraffe
# 3 ............ Gnu
# 4 .......... Llama
# 5 .......... Tiger