Mar-22-2021, 03:04 PM
(This post was last modified: Mar-22-2021, 03:05 PM by deanhystad.)
This is ugly. Duplicate code that never seems to be an exact duplicate.
But you can combine the benefits of the two with the new "walrus" operator :=
Pascal RULES!!
words = [] new_word = input('Enter a word\n') while new_word.lower() != 'stop': words.append(new_word) new_word = input('Enter word\n') print(words)I like this a little better.
while True: new_word = input('Enter a word\n') if new_word == 'stop': break words.append(new_word)No duplicate code, but it is slightly longer and "while True" as the "forever is only a short time" loop looks odd.
But you can combine the benefits of the two with the new "walrus" operator :=
words = [] print('Enter list of words, one per line. End list with "stop"') while (word := input()).lower() != 'stop': words.append(word)Short. No duplicate code.
Pascal RULES!!