Question: 1. Go to Zelle's textbook website, http://mcsp.wartburg.edu/zelle/python/ppics2/code/chapter08/. 2. Test all 5 files average3.py, average4.py, average5.py, average6.py and average7.py one by one. 3. With a single
1. Go to Zelle's textbook website, http://mcsp.wartburg.edu/zelle/python/ppics2/code/chapter08/.
2. 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).
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).
# 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()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
