##Name: Wurong Weng
##MacID: wengwr
##Sutdent Number: 1224989
##Date: Feb. 13, 2013

Fx = raw_input("Enter the name of a text file stores a sequence of numbers: ")
Fy = raw_input("Enter the name of the second text file stores a sequence of numbers: ")
print

infile = open(Fx,"r")
Lx = infile.readlines()
infile.close()
infile = open(Fy,"r")
Ly = infile.readlines()
infile.close()

n = len(Lx)
sumXY = 0
sumX = 0
sumY = 0
sumXX = 0
for i in range(n):
    Lx[i]=float(Lx[i])
    Ly[i]=float(Ly[i])
    sumXY += Lx[i]*Ly[i]
    sumX += Lx[i]
    sumY += Ly[i]
    sumXX += Lx[i]**2


m = (n*sumXY - sumX * sumY)/(n*sumXX - sumX**2)

print "The sequence of numbers in",Fx,"=",Lx
print "The sequence of numbers in",Fy,"=",Ly
print "The slope of the best fit line to the data, m=",m

##Design Question:
##    There are total four different summations in equation 1.I use the for loop
##    command to calculate each of these summations and store the calue in four
##    appropriate labels.

##Tsst Plan:
##    Test: 1
##    Input: [[1,2,3,4],[2,4,6,8]]
##    Expected Output: 2.0
##    Actual Output: 2.0
##    Result: PASS
##
##    Test: 2
##    Input: [["a",2,3,4],[2,4,6,8]]
##    Expected Output: Error
##    Actual Output: ValueError
##    Result: PASS
##
##    Test: 3
##    Inout: [[0,0,0,0],[2,4,6,8]]
##    Expected Output: Error
##    Actual Output: ZeroDivisionError
##    Result: PASS
