LAB7COMP. CSCE 160 Lab 7 Make sure you use proper style when you name variables/constants and align statements. Do not forget to put your name in the top comments of each of your programs. The format...

n/a


LAB7COMP. CSCE 160 Lab 7 Make sure you use proper style when you name variables/constants and align statements. Do not forget to put your name in the top comments of each of your programs. The format of your programs is very important when learning a programming language and bad style may be penalized with up to 30%. You shall write modularized programs wherein each task is in its own function. Divide and Conquer approach shall be applied. 1. Create a file "numbers.txt" that contains a sequence of integer values (one integer in each row). Write a Python program that reads the file "numbers.txt" and calculates and prints the average of all integer numbers in this file. Sample Ouput #1 (for numbers.txt: 1 2 3 4 5 6 8 12 34 10 20): Please input the name of the file to be opened: numbers.tx --- File Not Found! --- Sample Output #2 (for numbers.txt: 1 2 3 4 5 6 8 12 34 10 20): Please input the name of the file to be opened: numbers.txt Number # 1 is: 1 Number # 2 is: 2 Number # 3 is: 3 Number # 4 is: 4 Number # 5 is: 5 Number # 6 is: 6 Number # 7 is: 8 Number # 8 is: 12 Number # 9 is: 34 Number # 10 is: 10 Number # 11 is: 20 The average of 11 numbers/file = 9.55 2. Write a Python program that reads the file "numbers.txt" and writes all even values from this file into a new file called "even.txt". Sample Output #1: Please input the name of the file to be opened: numbers.tx --- File Not Found! --- Sample Output #2 (for numbers.txt: 10 12 1 3 5 34 2 5 7 9 44): Please input the name of the file to be opened: numbers.txt Found 11 numbers/file. Open the file numbers.txt to get the output. numbers.txt: 10 12 34 2 44 3. Write a Python program that asks the user to enter a file name and reads data from the file. The program shall be able to sum the digits in any positive integers. Sample Output #1: Please input the name of the file to be opened: numbers.tx --- File NOT Found! --- Sample Output #2 (for numbers.txt: 12345 222256 -3 123 -56784 555557 6345678 81234 121212): Please input the name of the file to be opened: numbers.txt For number 12345 the sum of digits is: 15 For number 222256 the sum of digits is: 19 Found an integer (-3), but it is negative. Will ignore! For number 123 the sum of digits is: 6 Found an integer (-56784), but it is negative. Will ignore! For number 555557 the sum of digits is: 32 For number 6345678 the sum of digits is: 39 For number 81234 the sum of digits is: 18 For number 121212 the sum of digits is: 9 Lab Assignment Submission Copy your source code from Spyder editor and paste it to a Word document. Take a screenshot of your output and attach it after the source code in the Word document. Only ONE Word document is expected.
Oct 24, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here