python中没有+运算符的求和

Need to get sum of x and y without `+` operator.

I trid to sum two number using adder.If we xor x and y (`x ^ y`) , we will get summation without carry. From `x & y` we can get carry. To add this carry in summation , call add function again. but its not give answer. where is the error in my code.

``````def add(a,b):
if a == 0:
return b

x = 10
y = 20
``````

File "main.py", line 4, in add

``````return add(a^b, a&b)                                                                                                                          File "main.py", line 4, in add

if a == 0:                                                                                                                                  RuntimeError: maximum recursion depth exceeded in comparison
``````

xsint

``````def add(a,b):
if a == 0:
return b
if b == 0:
return a

x = 10
y = 20
``````

``````def add(a,b):
if a == 0 or b==0:   # if either one is zero
return a or b         # return the non-zero one (or 0 if both are 0)
``````30