"""
	Addition:
	Input: a base b, a length n, and two positive n digit integers X and Y. 
	Intermediate variable: c, the carry. 
	Output: an integer Z represented by its digits such that Z = X + Y, or an error if X + Y cannot
		be represented as an n digit, base b integer. 
"""

import math
import random

def addition(b, n, X, Y):
	c = 0
	Z = []
	for i in range(0, n):
		s = X[i] + Y[i] + c
		Z.append(s%b)
		c = math.floor(s/b)
	if c != 0:
		Z.append(c)
	return Z

if __name__ == "__main__":
# A test case
	b = 10
	n = 30
	X = [random.randrange(0, 10) for i in range(0, n)]
	Y = [random.randrange(0, 10) for i in range(0, n)]
	print "X: ", X
	print "Y: ", Y
	Z = addition(b, n, X, Y)
	print "Z: ", Z


@@ -299,16 +299,119 @@
 random%0A%0A
+def integer_value(b, n, d_list):%0A%09v = 0%0A%09for i in range(n-1, -1, -1):%0A%09%09v = v*b + d_list%5Bi%5D%0A%09return v%0A%0A
 def addi
@@ -428,16 +428,16 @@
  X, Y):%0A
-
 %09c = 0%0A%09
@@ -552,16 +552,33 @@
 pend(c)%0A
+%09%09i += 1%0A%09i += 1%0A
 %09return 
@@ -578,16 +578,19 @@
 return Z
+, i
 %0A%0Aif __n
@@ -762,28 +762,80 @@
  %22, 
-X%0A%09print %22Y: %22, Y%0A%09Z
+integer_value(b, n, X)%0A%09print %22Y: %22, integer_value(b, n, Y)%0A%09Z, Z_length
  = a
@@ -868,11 +868,39 @@
  %22Z: %22, 
-Z
+integer_value(b, Z_length, Z)
 %0A%0A

Modify the output format.