Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you will write a Python program that reads a file called assignment1-2.txt and calculates the average of numeric data based on certain

image text in transcribedimage text in transcribedimage text in transcribed

In this assignment you will write a Python program that reads a file called assignment1-2.txt and calculates the average of numeric data based on certain condition(s). Let us assume that ID4 refers to the last 4-digits of a student's ID (EMPL_ID). The lines of the file has the following format: every odd-numbered line, starting with the first, line has an ID4 and the every even-numbered line, starting with the second line, has a numeric data point. This is a generalization of the format: ID4> Here are the first 10 lines of the file: 218015657425377830431841232189 In this sample, the first pair of lines is a numeric data point tor the student whose ID4 is 2180 . The numeric data is 1. Similarly, the second pair of lines is a numeric data point for the student whose ID4 is 5657 , and the numeric data is 425 Your program should read through the entire file, and calculate the average of all the numeric data where the ID4 matches your own. Your program should print a single numeric value -- the average -- as an int (in other words, no decimal figures). The numeric data can be either positive or negative. Each student has 1000 numeric data points appearing randomly with the file. A startup program, called main.py, has been provided that reads the data file and processes each line. You should use that program as a starting point. Here is the startup program (main.py): \# sample python code that opens up the assignment file and starts \# reading it line by line using a for loop with open('assignment1.txt', 'r') as file_handle: for line in file_handle: line_str = line.strip() \# come up with your own algorithm \# your program should print this average in int format (i.e., no decimals) You can develop this program in Jupyter-lab or in any IDE of your choice (Spyder, PyCharm, etc.). In either case, you should copy and paste your complete program into main.py in this folder and submit it there. Here are some restrictions: - You are forbidden to import numpy or pandas for this assignment - You should work individually - You are not allowed to import any additional libraries - Whether you work using Jupyter Lab or any other IDE, your main python script and the data file should both reside in the same folder. You need to download the assignment1.txt in the same directory from which you are running main.py program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

3. Job rotation is used for all levels and types of employees.

Answered: 1 week ago