def inp():
try:
k=input("enter")
l=int(k)
return l
except :
inp()
print(inp())
enterll
enter6
None
Process finished with exit code 0
def inp():
try:
k=input("enter")
l=int(k)
return l
except :
inp()
print(inp())
enterll
enter6
None
Process finished with exit code 0
You need to return the result of the recursive call in the except
block; otherwise, None
is implicitly returned as you did not explicitly return anything.
def inp():
try:
k = input("enter")
l = int(k)
return l
except ValueError:
return inp()
After handling the exception, there is not return value. This is the problem when you have multiple returns. You can fix it with one return
def inp():
try:
k=input("enter")
l=int(k)
except :
l = inp()
return l
or add a return in the exception handler
def inp():
try:
k=input("enter")
l=int(k)
return l
except :
return inp()