Need Help ?
Have a Question ?

(Solved): 2. A Simple Spring Test Rig Measures Weights Hung From A Spring And The Static Displacement At Each ...


2. A simple spring test rig measures weights hung from a spring and the static displacement at each weight. The springs are s


It is very strongly suggested that reading the data and calculating stiffness correctly is done first. Getting the format out
2. A simple spring test rig measures weights hung from a spring and the static displacement at each weight. The springs are supposed to be linear, following the relation F=k8, where Fis the force applied to the spring, kis the spring constant, and is the displacement in the spring. We can see, when given values of force and displacement, we can find k=F/6. Femg The data collected from one run of this rig is given in the file WO5_02 Springbata.txt, which is available on Look over that file to see how the headers are set up and note the numerical formats. The last line is blank. Note that the file could have any number of data rows in it, not just the 10 shown. Your program should accommodate different sizes of data files without changing the code for data file. You may assume that there will be 4 header lines before the first data line: A comment, the column titles, the column units, and a blank line. You should read the header lines to know what to write to the output file's headers Write a Python program that reads in the headers and data from that file. The program should be able to accommodate any size of file. For each data point in the file, calculate a spring constant k for the given weight and displacement. This should be in N/m (not N/mm). Keep track of these values. For output, create a file called HW05_02_out.txt. It should have • The same comment as the input file. • Three columns, the first two are the weight and displacement from the input file. The third column is the spring constant calculated for each row, with the column header title stiffness and header units "IN/m)". • A header line following the units should consist of dashes for each header, as wide as the header title for that column. • Make each column of the output file 20 characters wide. The format specification for all floats should use a 20 character wide field and show 3 digits to the right of the decimal place. See the example output below to be sure how this should look. It is very strongly suggested that reading the data and calculating stiffness correctly is done first. Getting the format output correct will take some time and some fine-tuning. Remember that the code should work for an input data file with any number of data rows without adjustment to the code. As an example, a data file with 5 data lines is shown below (and available as HWO5_ExampleSpringData.txt one . Spring Test Data, February, 2020 weight displacement (N) ) 0.968 2.022 2.997 0.6520 1.3066 2.0459 It is very strongly suggested that reading the data and calculating stiffness correctly is done first. Getting the format output correct will take some time and some fine-tuning. Remember that the code should work for an input data file with any number of data rows without adjustment to the code As an example, a data file with 5 data lines is shown below (and available as HWO5_ExampleSpringData.txt on CatCourses). Spring Test Data, February, 2020 weight displacement (N) (mm) 0.968 2.022 2.997 3.965 4.984 0.6520 1.3066 2.0459 2.5755 3.4614 And the resulting output file (available as HW05_ExampleSpringData_out.txt): Spring Test Data, February, 2020 weight displacement (N) (mm) stiffness (N/m) 2.968 2.022 2.997 3.965 4.984 0.652 1.307 2.046 2.575 3.461 1484.663 1547.528 1464.881 1539.507 1439.880

Expert Answer


fileToRead="HW05_02_SpringData.txt" fileToWrite="HW05_02_out.txt" f=open(fileToRead) comment=f.readline().strip() titles=f.readline().strip() t1,t2=titles.split() units=f.re
We have an Answer from Expert Buy This Answer $6