Unexpected indent


Please see uploaded image.

I a busy with The Boredless Tourist project… and I’m trying to run the travelers_destination function and it should print out 1, it it says my return is on an unexpected indent. I did it exactly like the video and tried changing things. Not working please check my code and terminal :grinning:

1 Like

I’ am afraid I’ve not tried this particular problem but based on the error code it appears to be either on or before the line-

return traveler_destination_index

Be very careful with newlines and returns in python. Whilst features like lists or open parantheses allow multi-line comments without much issue this is not always the case.
If you must imlement a newline the \ character can be used to split the line but use it sparingly when all other options make the code less readable.

1 Like

Hi there, welcome to the forums.

Visually, I can’t see what the issue is.

Can you please post the code to the forum, so we can run it.

All you need to do is look for the </> icon in the menu bar which appears at the top of the text box while you type.

capture

Press Enter to go to a blank line, click that icon, and you will see this:

capture_r

Just copy and paste your code directly from the lesson editor into that highlighted portion, and we’ll be able to run exactly the program you did to get that error. :slight_smile:

1 Like

Hi there thanx for the help, here is the code:

destinations = ['Paris, France', 'Shanghai, China', 'Los Angeles, USA', 'São Paulo, Brazil', 'Cairo, Egypt']

test_traveler = ['Erin Wilkes', 'Shanghai, China', ['historical site', 'art']]

def  get_destination_index(destination):
  destination_index = destinations.index(destination)
  return destination_index

print(get_destination_index('Hyderabad, India'))

def get_traveler_location(traveler):
  travelers_destination = traveler[1]
  traveler_destination_index = get_destination_index(traveler_destination)
    return traveler_destination_index
  
test_destination_index = get_traveler_location(test_traveler)
print(test_destination_index)

Have you covered the functions part of the course you are on?
Your indentation is not consistent and is consequently throwing an error. The error code is directing you straight to the issue in this case. Indentation in Python is a requirement of grouping statements into blocks and, as in this case, will throw errors when it is not formatted correctly.

3 Likes

thank you I will make sure all indents are the same

2 Likes