[Tutor] tiny, little issue with list

Alan Gauld alan.gauld at yahoo.co.uk
Sun Mar 19 12:01:52 EDT 2017


On 19/03/17 12:17, Rafael Knuth wrote:
> LogActivities = []
> prompt = ("What have you done today? ")
> prompt += ("Enter 'quit' to exit. ")

I'm not sure why you put that on two lines but
thats just a nit pick...

> while True:

This will loop forever unless you explicitly break,
return or hit an exception. You should fix that.

>     activity = input(prompt)
>     LogActivities.append(activity)

You append activity regardless of what it is so
obviously you include the 'quit'.

>     if activity == "quit":
>         print("Let me recap. This is what you've done today: %s." % ",
> " .join(LogActivities))

Then after appending it you test to see if its
quit then print a message(but don;t actually
quit, see above)


To avoid the append you could put the test for
quit at the top of the loop and put the append
lines in an else:

if activity == 'quit':
   print.... # and break?
else:
   append....


HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list