{"id":1051,"date":"2021-12-01T13:16:13","date_gmt":"2021-12-01T13:16:13","guid":{"rendered":"https:\/\/ethosspace.com\/programmers\/?p=1051"},"modified":"2021-12-01T13:31:04","modified_gmt":"2021-12-01T13:31:04","slug":"indentationerror-expected-an-indented-block","status":"publish","type":"post","link":"https:\/\/ethosspace.com\/programmers\/indentationerror-expected-an-indented-block\/","title":{"rendered":"IndentationError: expected an indented block How to resolve"},"content":{"rendered":"\n<p>While running any python program if the user receives an error like IndentationError: expected an indented block. This means indentations are not proper.<\/p>\n\n\n\n<p>Let&#8217;s see the below example and how to solve the error  IndentationError: expected an indented block. <\/p>\n\n\n\n<p>Below code with Error <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>a = 4\nb = 5\nif a &gt; b:\nprint (&#39;A is maximum&#39;)\nelse:\nprint (&#39;B is maximum&#39;)<\/code><\/pre><\/div>\n\n\n\n<p>Output<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>File &quot;&lt;string&gt;&quot;, line 4\n    print (&#39;A is maximum&#39;)\n    ^\nIndentationError: expected an indented block<\/code><\/pre><\/div>\n\n\n\n<p>If we observe in code that there is indentation available for if and else condition, as a result, python throws an error message.<\/p>\n\n\n\n<p>To resolve error we need to provide <a href=\"https:\/\/docs.python.org\/3\/tutorial\/controlflow.html\" rel=\"nofollow\" title=\"https:\/\/docs.python.org\/3\/tutorial\/controlflow.html\">indentation <\/a>to statements after If condition.  So we try to provide uniform spaces for statements after if conditions like below <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>a = 4\nb = 5\nif a &gt; b:\n    print (&#39;A is maximum&#39;)\nelse:\n    print (&#39;B is maximum&#39;)<\/code><\/pre><\/div>\n\n\n\n<p>After indentation output is <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>B is maximum<\/code><\/pre><\/div>\n\n\n\n<p>\u00a0In conclusion, the indentation needs to be consistent. It is recommended to use 4 spaces for indentation in Python.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While running any python program if the user receives an error like IndentationError: expected an indented block. This means indentations are not proper. Let&#8217;s see the below example and how to solve the error IndentationError: expected an indented block. Below code with Error Output If we observe in code that there is indentation available for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[11],"tags":[],"class_list":["post-1051","post","type-post","status-publish","format-standard","hentry","category-running-code-and-program"],"aioseo_notices":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"sparkling-featured":false,"sparkling-featured-fullwidth":false,"tab-small":false},"uagb_author_info":{"display_name":"program45_-rt8nb","author_link":"https:\/\/ethosspace.com\/programmers\/author\/program45_-rt8nb\/"},"uagb_comment_info":0,"uagb_excerpt":"While running any python program if the user receives an error like IndentationError: expected an indented block. This means indentations are not proper. Let&#8217;s see the below example and how to solve the error IndentationError: expected an indented block. Below code with Error Output If we observe in code that there is indentation available for&hellip;","_links":{"self":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/1051","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/comments?post=1051"}],"version-history":[{"count":5,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/1051\/revisions"}],"predecessor-version":[{"id":1058,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/1051\/revisions\/1058"}],"wp:attachment":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/media?parent=1051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/categories?post=1051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/tags?post=1051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}