add without carry

MonkeeSage MonkeeSage at gmail.com
Fri Sep 15 05:48:56 EDT 2006


Hugh wrote:
> Sorry, here's an example...
>
> 5+7=12
>
> added without carrying, 5+7=2
>
> i.e the result is always less than 10

def add(a, b, c=10):
  an = a + b
  if an >= c:
    an -= c
  return an

add(5, 7) # = 2

?

Regards,
Jordan




More information about the Python-list mailing list