Boredless challenge exercise

Hi,

I went through the whole exercise and it all went well. I watched the walk-through video as well but I am puzzled at the last part ''get_attractions_for_traveler" function of the exercise. In the following code:

def get_attractions_for_traveler(traveler):
traveler_destination = traveler [1]
traveler_interests = traveler [2]
traveler_attractions = find_attractions(traveler_destination, traveler_interests)
interests_string = 'Hi ’ + traveler[0] + ', we think you will like these places around ’ + traveler_destination + ': ’
for i in range(len(traveler_attractions)):
if traveler_attractions [-1] == traveler_attractions[i]:

  interests_string += 'the ' + traveler_attractions [i] + '.'
***else:***

*** interests_string += 'the ’ + traveler_attractions [i] + ‘,’***
return interests_string
smills_france = get_attractions_for_traveler([‘Dereck Smill’, ‘Paris, France’, [‘monument’, ‘museum’]])
print (smills_france)

In the second part (highlighted), the main purpose was to check whether the traveler has more than one interest so that we can add comma in between the attractions and when the search is done, is to add a full stop.

That being said, when I played around and added some more interests as above ''monument" and “museum”, the search returned “monument” only and a comma with nothing else.

Any thoughts?

Thanks :slight_smile:

Executable code (try copying and running from your post) and examples of what you’re describing would help (what comma? easier to see the difference if you show both) (played around? what code is that exactly?)

…also, if you join a single value with comma in-between, then you’ll end up with zero commas because there are zero things between one thing, so it’s kinda pointless to check whether there’s one or there’s many, you’d join on comma either way. The thing that would be different is if there are zero.

Thanks for your message, I have added examples with screen shots down below:
Here attractions in France has one museum and one monument:

This means that the second part of the loop should be executed

So, I edited the traveler data as shown here to include both museum and monument:

But, this returns one attraction with a comma and nothing else. It should have returned both attractions not just one!

Hope that makes sense!

Thanks for your help!

that’s not a loop, it runs once

2 Likes