-1

my code and the terminal .

file = "ex25.py", line 27
words=sort_sentence(sentence)

IndentationError: unindent does not match any other indentation level

The code I wrote in ex25 is:

def print_first_and_last_sorted(sentence):
       words =sort_sentence(sentence)
        print_first_word(words)
        print_last_word(words)
Gary
  • 13,303
  • 18
  • 49
  • 71
  • Possible duplicate of [I'm getting an IndentationError. How do I fix it?](https://stackoverflow.com/questions/45621722/im-getting-an-indentationerror-how-do-i-fix-it) – Gino Mempin Jun 06 '19 at 08:28

2 Answers2

1

After you define function with the first line, in the second line you need to use proper indentation or spaces. The standard is 4 spaces (4 space keystrokes) or 1 tab.

def print_first_and_last_sorted(sentence):
    words =sort_sentence(sentence)  # This line and next should be spaced 4 times with
    print_first_word(words)         # respect to the above one
    print_last_word(words)

Your second line is not indented properly. You can compare it with the next lines. They all should be vertically parallel at their start points.

MNK
  • 634
  • 4
  • 18
0

I can't comment but from both the edit and the original post, therefore I can't tell what the indentation actually is.

Python indentation works like blocks of code, similar to other languages except without the curly braces. For example:

def print_first_and_last_sorted(sentence):
    words = sort_sentence(sentence)
    print_first_word(words)
    print_last_word(words)

You may have mixed up spaces & tabs. From this answer, try searching and replacing to replace them with a few spaces.

spliitzx
  • 11
  • 2
  • 4