Question: # average7.py def main(): fileName = input(What file are the numbers in? ) infile = open(fileName,'r') sum = 0.0 count = 0 line = infile.readline()
# average7.py def main(): fileName = input("What file are the numbers in? ") infile = open(fileName,'r') sum = 0.0 count = 0 line = infile.readline() while line != "": # update sum and count for values in line for xStr in line.split(","): sum = sum + eval(xStr) count = count + 1 line = infile.readline() print(" The average of the numbers is", sum / count) main()
Test all file average7.py .
3. With a single .txt file, revise file with line-by-line explanation. (Using # to add comment/explanation).
One file with line-by-line explanation, followed by one running result with IDLE shell information (try to use the same testing inputs to see the differences between each .py files).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
