Boredless Tourist Final String solution (i.e ' and ', ', ' attraction string)

I just wanted to share my final return string for loop . I think it’s a lot easier than the video solution. For brevity sakes, I will just post the last function where you can find the logic for when the program should add either a ‘,’ or ‘and’

Make sure you duplicate a few attractions with the same tags so you can test it yourself in your code.

Good luck

def get_attractions_for_traveler(traveler):
    traveler_destination = traveler[1]
    traveler_interest = traveler[2]
    
    traveler_attractions = find_attractions(traveler_destination,traveler_interest)
    
    interests_string = 'Hi '
    
    interests_string += traveler[0]
    
    interests_string += ", we think you'll like these places around " + traveler_destination + ': '
    
    for attraction in traveler_attractions:
        interests_string += attraction
        if attraction == traveler_attractions[-2]:
            interests_string += ' and '  
        elif attraction != traveler_attractions[-1]:
            interests_string += ', '     
    
    interests_string += '.'
        
    return interests_string

1 Like