[ create a new paste ] login | about

Link: http://codepad.org/xTbLLXBJ    [ raw code | output | fork ]

Python, pasted on Jul 4:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import exceptions
MAX_INT  = 1000
MIN_INT = -1000

def str2int(s):
  for i in range(MIN_INT,MAX_INT):
    if s == str(i):
      return i
  raise exceptions.OverflowError

def add2strings(s,t):
  return str(str2int(s)+str2int(t))

print add2strings("170","-300")
print add2strings("170","-1001")


Output:
1
2
3
4
5
6
7
8
9
-130
Traceback (most recent call last):
  Line 15, in <module>
    print add2strings("170","-1001")
  Line 12, in add2strings
    return str(str2int(s)+str2int(t))
  Line 9, in str2int
    raise exceptions.OverflowError
OverflowError


Create a new paste based on this one


Comments: