Complete the following program that is, write the functions getInputs, countSpac
ID: 3843923 • Letter: C
Question
Complete the following program that is, write the functions getInputs, countSpaces (), minMax (), and printSummary (): def main (): fname = getInputs () #get the file name from the user infile = open (fname, "r") #open the file for reading resultList = list () #initialize result list to empty list for line in infile: num = countSpaces (line) #return the number of spaces in line result List .append (num) m, M = minMax (resultList) #compute the min and max spaces per line print Summary (m, M) # print the min and max spaces (including explanation)Explanation / Answer
Below is the modified program with all the functions written Note: It is being developed with Python 3
def getInputs():
fname = input()
return fname
def countSpaces(line):
count = 0
for char in line:
if char == ' ':
count = count +1
return count
def minMax(resultList):
min = 0
max = 0
if(len(resultList) == 0):
return min,max
min = resultList[0]
max = resultList[0]
for numb in resultList:
if(min is None):
min = numb
if(numb > max):
max = numb
if(numb < min):
min = numb
return min,max
def printSummary(m,M):
print("Min Spaces = "+ str(m)+ " Max Spaces = "+ str(M))
def main():
fname = getInputs()
infile = open(fname,"r")
resultList = list()
for line in infile:
num = countSpaces(line)
resultList.append(num)
m,M = minMax(resultList)
printSummary(m,M)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.