The except
keyword must be at the same indent level as try
:
try:
if name > 3:
print("hello")
except:
print("There is something wrong")
Although there’s precious little in there that can cause an exception. So, on the off chance you wanted to print either of those strings based on the value of name
, that would be:
if name > 3:
print("hello")
else:
print("There is something wrong")
solved I have a problem using ‘except’ code in python [closed]