-2

I have a simple python code but returns me this error -> IndentationError: unindent does not match any outer indentation level!

favorite_languages = {"jen": "python","sarah": "c","edward": "ruby","phil": "python",}

friends = ["phil", "sarah"]

    for name in favorite_languages.keys():

        print(name.title())

        if name in friends:
            print("Hi " + name.title() + ", I see your favorite language is " + favorite_languages[name].title())
  • 2
    You don't need that `for` loop indented. Also [this](https://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level) might be useful. Although I would suggest you work with an IDE that takes care of indentation for you. – 0buz Mar 03 '20 at 18:31
  • @0buz I'm not sure any IDE could fix that, only tell them that it's incorrect – roganjosh Mar 03 '20 at 18:46
  • 1
    No need to get pedantic about it :) Any modern IDE offers highlighters/PEP8 reformatting in one form or another. – 0buz Mar 03 '20 at 18:58
  • 1
    @roganjosh For what it's worth, PyCharm's "Reformat Code" command does fix it. – AMC Mar 03 '20 at 19:11
  • @AMC fair. I wouldn't have guessed that and I'd be a little concerned with its potency to decide and the potential to get the intent wrong, but my statement was also wrong. Thanks for the correction – roganjosh Mar 03 '20 at 19:23

1 Answers1

0

Indentation error is at for loop,

favorite_languages = {"jen": "python", "sarah": "c",
                  "edward": "ruby", "phil": "python", }

friends = ["phil", "sarah"]

# forloop
for name in favorite_languages.keys():
    print(name.title())
    if name in friends:
        print("Hi " + name.title() + ", I see your favorite language is " +favorite_languages[name].title())

just install autopep8, it will format your code

zen29d
  • 61
  • 7