While running any python program if the user receives an error like IndentationError: expected an indented block. This means indentations are not proper.
Let’s see the below example and how to solve the error IndentationError: expected an indented block.
Below code with Error
a = 4
b = 5
if a > b:
print ('A is maximum')
else:
print ('B is maximum')
Output
File "<string>", line 4
print ('A is maximum')
^
IndentationError: expected an indented block
If we observe in code that there is indentation available for if and else condition, as a result, python throws an error message.
To resolve error we need to provide indentation to statements after If condition. So we try to provide uniform spaces for statements after if conditions like below
a = 4
b = 5
if a > b:
print ('A is maximum')
else:
print ('B is maximum')
After indentation output is
B is maximum
In conclusion, the indentation needs to be consistent. It is recommended to use 4 spaces for indentation in Python.