doubt in python

why am i getting an error in this code in python ?

def check(a):
if a == 0 :
	print "we are in if statement"
else:
	print "we are in else statement"
	print "to be executed inside else"
check(0)
	print "to be executed later"

Give indentation after def check(a):

and there should’nt be any indentation after check(0)

1 Like

It is basically an Indentation Error.

Indentation is important because you can’t write a loop or a function without it in python or may end up with ambiguous results.

Not only in Python, it should be followed in any other programming language because indentation is a very good practice and it makes the code more readable and understandable to others.

PS Please try compiling your code once and I would suggest you use a better Python IDLE because you would have been prompted with a dialog echoing “Indentation error”.

The rest is self-explanatory.

Happy coding.

1 Like

Select your code which inside the function and press “tab” ,save it and run it!

1 Like