[Tutor] List Python Question..Please help

Alan Gauld alan.gauld at btinternet.com
Fri Sep 27 10:01:00 CEST 2013


On 27/09/13 06:48, Jacqueline Canales wrote:
> So I have been trying to do this program using ifs and or loops.
> I am having a hard time solving this question, If you could please
> assist me in the right direction.

Happy to. We won't do the homework for you but we will ask leading 
questions and give hints.

> I know below it prints the entire list of composers but i dont know  how
> to do the program above.

OK, breaking it into three parts:

1) print names from the list - you can do that already

2) test if a name starts and ends with the same letter
    - Amit has shown you how to get the letters, do you
      know how to test for equality (using the == operator)?

3) Filter the printout based on the test in (2)
    - Do you know how to use an if statement to take
      action depending on the outcome of a test?

Your code should then look like

for person in persons:
     if <your test here>
        print person


If there are still things you are unclear about
ask here and we will break it down further.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list