Monday, 15 April 2013

math - Code trouble with python -



math - Code trouble with python -

i'm having problem here. cs assignment, have have python take info file on pc , run info through program.

so, code works fine on http://repl.it/languages/python, not in python. i'm assuming because line of code has python 2.0 lines of code? can't seem prepare it. can guys help? and, little question except one. have input code in programme take info file , run through programme stated above. have this.

import math def mean(values): average = sum(values)*1.0/len(values) homecoming average def deviation(values): length = len(values) m = mean(values) total_sum = 0 in range(length): total_sum += (values[i]-m)**2 root = total_sum*1.0/length homecoming math.sqrt(root) def median(values): if len(values)%2 != 0: homecoming sorted(values)[len(values)/2] else: midavg = (sorted(values)[len(values)/2] + sorted(values)[len(values)/2-1])/2.0 homecoming midavg def main(): x = [15, 17, 40, 16, 9] print mean(x) print deviation(x) print median(x) main()

how have programme take info file , run through program? info bunch of numbers, way. it's been giving me problem hours now. if can help out.

this know opening/closing file stuff far

f = open("filename.txt") info = f.readlines() f.close()

apparently using python2.x:

i'm assuming because line of code has python 2.0 lines of code?

so yes, do have problem: in python3.x, print became function.

thus, prints need changed:

print mean(x) print deviation(x) print median(x)

becomes

print(mean(x)) print(deviation(x)) print(median(x))

also, part opening , closing files unclear.

python math

No comments:

Post a Comment