Question: This program will not work in python 3.6 I can not figure out how to re- type it so it works in python 3.6 import

This program will not work in python 3.6 I can not figure out how to re- type it so it works in python 3.6

import sys

def readFile(filename):

f=open(str(filename),'r')

numbers = [int(num) for num in f]

return numbers

def getSum(ar):

sum=0

for number in ar:

sum = sum + int(number)

return sum

def getCount(ar):

count=0

for num in ar:

count = count + 1

return count

def getAverage(ar):

avg= float(getSum(ar))/float(getCount(ar))

return avg

def getMax(ar):

maximum = ar[0]

for num in ar:

if num > maximum:

maximum = num

return maximum

def getMin(ar):

minimum = ar[0]

for num in ar:

if num < minimum:

minimum = num

return minimum

def getRange(ar):

maxim = getMax(ar)

minim = getMin(ar)

return maxim - minim

def sort(ar):

length =getCount(ar)

i = 0

j = 0

while i < length:

j=0

while j

if ar[j] > ar[j+1]:

temp = ar[j+1]

ar[j+1] = ar[j]

ar[j] = temp

j=j+1

i=i+1

def getMedian(ar):

sort(ar)

length = getCount(ar)

if length % 2 is 0 :

return (ar[length/2 - 1])+ float(ar[length/2])/2.0

return ar[length/2]

def getMode(ar):

sort(ar)

length = getCount(ar)

maxim = 1

mode = []

if length is 1 or 0:

if length is 1:

mode.append(str(ar[0]))

return mode

else:

return mode

i = 0

count = 1

while i < length-1:

if ar[i] != ar[i+1]:

count=1;

else:

count = count + 1

if count > maxim:

maxim = count

i = i + 1

if ar[i] == ar[i-1]:

count = count + 1

if count > maxim:

maxim = count

i = 0

count = 1

while i < length-1 :

if ar[i] != ar[i+1]:

count=1;

else:

count = count + 1

if count == maxim:

mode.append(str(ar[i]))

i = i + 1

if ar[i] == ar[i-1]:

count = count + 1

if count == maxim:

mode.append(str(ar[i]))

return mode

choice = 'y'

while choice is 'y' :

filename =""

try:

filename=input("Enter File Name: ")

array = readFile(filename)

except IOError:

print ("Invalid file name ",filename)

choice = input("Would you like to evaluate another file? (y/n): ")

continue

count = getCount(array)

if count is 0:

print ("There are no numbers in ",filename)

choice = input("Would you like to evaluate another file? (y/n): ")

continue

sum = getSum(array)

average = getAverage(array)

print ("Sum :" ,sum)

print ("Count: ",count)

print ("Average: ",average)

print ("Maximum: ", getMax(array))

print ("Minimum: ", getMin(array))

print ("Range: ",getRange(array))

print ("Median: ", getMedian(array))

mode = getMode(array)

i=0

sys.stdout.write('Mode : [')

for num in mode:

sys.stdout.write(num)

if i!=len(mode) -1:

sys.stdout.write(',')

i = i + 1

sys.stdout.write('] ')

choice = input("Would you like to evaluate another file? (y/n): ")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!