Python Forum
Stranger in our midst
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stranger in our midst
#2
Using a while loop is the right idea. There are many ways to approach this. I personally prefer using a break to exit the loop when the stop condition is satisfied.

words = []

while True:
    new_word = input('Enter a word\n')  # str() is not needed because input() returns a string by default
    if new_word.lower() == 'stop':  # using lower() makes this comparison work for 'STOP', 'Stop', etc.
        break
    words.append(new_word)

print(words)
Reply


Messages In This Thread
Stranger in our midst - by tfak - Mar-22-2021, 09:16 AM
RE: Stranger in our midst - by GOTO10 - Mar-22-2021, 11:40 AM
RE: Stranger in our midst - by Serafim - Mar-22-2021, 01:21 PM
RE: Stranger in our midst - by deanhystad - Mar-22-2021, 03:04 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020