Why am I receiving a python error expecting an indented block?

482    Asked by Dannasahi in Python , Asked on Aug 8, 2023

 I want to execute the below-mentioned code:

Def example (p,q):
A = p . find (“ “)
B = q . find (“ “)
Str_p = p [0:a]
Str_q = p [b+1 : ]
If str_p == str_q:
Result = true
Else : 
Result = false
Return result

 I am seeing the error  IndentationError : expected an indented block Why am I seeing a Python error ‘expected an indented block’ ?

Answered by Elizabeth Clark

The error message ‘ expected an indented block error’ is seen when various tabs and spaces are mixed. When you don’t possess proper indents included in the compound statement and the user specific functions, the error message is seen. Python wants the code to be indented and spaced aptly. Ensure that the tabs and spaces are not mixed and in case you are deploying tabs then use only tabs, and if you are using spaces, then stick to that.


The code can be modified as below:

If str_p == str_q:
Result = True
Else:
Result = false
Return result
To
Return str_p == str_q

The Python online training offered at JanBask Training gives you an experience like offline classes thereby saving the students from the tiring journey to travel to the physical locations. The course provides a total Python discipline’s preparation by touching on every core concept from basic to advanced thereby making your job ready to face the tough competitive market.



Your Answer

Interviews

Parent Categories