不使用+,实现加的操作

  1. #! /usr/bin/env python
  2. # coding: utf-8
  3.  
  4. def newadd(x,y):
  5.     if not y:
  6.         return x
  7.     sum1=x^y
  8.     temp=(x>y)<<1
  9.     return newadd(sum1,temp)
  10.  
  11.  
  12.  
  13. if __name__=='__main__':
  14.     a=int(raw_input("please inter the first number:"))
  15.     b=int(raw_input("please inter the second number:"))
  16.     print newadd(a,b)

整体思路是通过位的运算来实现。