def bin(a):
e=str(a)
for char in e:
b=char
c=ord(b)
d=bin(c)
print(d)
it says recursion error
By naming your function bin
you have overridden builtin bin
function.
i know,but i works
except for the recursion error
A recursion is a repetition of itself.
A recusive function is a function which calls itself.
Consider this:
def recursion():
print("recursion")
recursion()
The function recursion() calls the function recursion() which calls
the function recursion() which calls the function recursion() which
calls the function recursion() and so on. This cannot go on forever,
because every function call consumes ressources like memory or CPU
cycles. Therefore Python aborts these recursive calls at some point
with a RecursionError.
Now, you have a function bin();
def bin(a):
d=bin(c)
Function bin() calls function bin() which calls function bin() which
calls function bin(), and so on.
Simple solution: Rename your function:
def my_bin(a):
e=str(a)
for char in e:
b=char
c=ord(b)
d=bin(c)
print(d)
Now, my_bin() just calls bin() and everything is fine.