Question: # average1.py def main(): n = eval(input(How many numbers do you have? )) sum = 0.0 for i in range(n): x = eval(input(Enter a number

# average1.py def main(): n = eval(input("How many numbers do you have? ")) sum = 0.0 for i in range(n): x = eval(input("Enter a number >> ")) sum = sum + x print(" The average of the numbers is", sum / n) main()

______________________________________________________________________

# average2.py def main(): sum = 0.0 count = 0 moredata = "yes" while moredata[0] == "y": x = eval(input("Enter a number >> ")) sum = sum + x count = count + 1 moredata = input("Do you have more numbers (yes or no)? ") print(" The average of the numbers is", sum / count) main()

_________________________________________________________________________________

# average3.py def main(): sum = 0.0 count = 0 x = eval(input("Enter a number (negative to quit) >> ")) while x >= 0: sum = sum + x count = count + 1 x = eval(input("Enter a number (negative to quit) >> ")) print(" The average of the numbers is", sum / count) main()

_______________________________________________________________________________

# average4.py def main(): sum = 0.0 count = 0 xStr = input("Enter a number ( to quit) >> ") while xStr != "": x = eval(xStr) sum = sum + x count = count + 1 xStr = input("Enter a number ( to quit) >> ") print(" The average of the numbers is", sum / count) main()

____________________________________________________________________________

# average5.py def main(): fileName = input("What file are the numbers in? ") infile = open(fileName,'r') sum = 0.0 count = 0 for line in infile: sum = sum + eval(line) count = count + 1 print(" The average of the numbers is", sum / count) main()

_________________________________________________________________________

Test all 5 files average3.py, average4.py, average5.py, average6.py and average7.py one by one.

3. With a single .txt file, revise all 5 files with line-by-line explanation. (Using # to add comment/explanation). (See sample from OVERVIEW for average1.py)

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

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!