[Tutor] Beginners question
Alex Kleider
akleider at sonic.net
Mon Mar 30 20:31:26 EDT 2020
On 2020-03-30 14:11, Michael Langdon wrote:
> Hi there,
>
>
> I have been tasked to use a while loop to repeatedly ask the user to
> enter
> a word.
>
> If the word is not 'quit', then add it to the list of words collected
> so
> far, in lower case. Then ask for the next word and so on.
>
> If they enter 'quit', do not add this word to the list, but print the
> list
> of words collected so far and exit the program.
>
> My input.
> a = input("Enter a word: ")
> sentence = sentence , a
> while a != ("quit"):
> sentence = sentence , a
> a = input("Enter a word: ")
> print(sentence)
>
> My output.
> Enter a word: orange
> ((), 'orange')
> Enter a word: apple
> (((), 'orange'), 'orange')
> Enter a word: quit
> ((((), 'orange'), 'orange'), 'apple')
>
>
> Can you help me with this?
Do you know about the key word 'break'?
use it as follows:
while True:
# get input
# if input means quit
break # break out of the loop
# proceed with whatever you want to do
Another key word worth knowing about is 'continue'
More information about the Tutor
mailing list