write a python program (i.E. a series of function definitions with one of these
ID: 3654859 • Letter: W
Question
write a python program (i.E. a series of function definitions with one of these functions acting as the main function of your program) that does the following. 1. open an input file and then read and process the numbers from the user. a. you must obtain the name of the input file from the user. 2. open an output file and write results to this file: a. the name of the output file shall be avg_INPUT_FILE_NAME, where INPUT_FILE_NAME is the name of the input file obtained from the user. 3. the input file shall:a.contain zero or more numbers on each lin. each number on a text line shall be seperated by one or more spaces. b. contain zero or more text lines. 4. for each text line in the input file: a. compute the avg of all even negative numbers found on the text line b. compute the avg of all odd positive numbers found on the text line c. compute the avg of all numbers found on the text line 5. the output file shall: a. contain a line of text for each txdt line in the input file. b. contain the three averages on a single line of text. the avg should be written on a line of text in order 4.a, 4.b, and 4.c. the three averages should be seperated by a tab character and be written in floating point notation with four digits to the right of the decimal point. c.) when the input text line does not contain any numbers, then the output file shall contain a blank line. d.) when the input text line does not contain any even negatice numbers, then the output file shall contain the string value "none" for this average. e) when the input text line does not contain any odd positive numbers, then the output file shal contain the string value "none" for this avg.Explanation / Answer
>>> s = 'Hello, world.' >>> str(s) 'Hello, world.' >>> repr(s) "'Hello, world.'" >>> str(1.0/7.0) '0.142857142857' >>> repr(1.0/7.0) '0.14285714285714285' >>> x = 10 * 3.25 >>> y = 200 * 200 >>> s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '...' >>> print s The value of x is 32.5, and y is 40000... >>> # The repr() of a string adds string quotes and backslashes: ... hello = 'hello, world ' >>> hellos = repr(hello) >>> print hellos 'hello, world ' >>> # The argument to repr() may be any Python object: ... repr((x, y, ('spam', 'eggs'))) "(32.5, 40000, ('spam', 'eggs'))" Here are two ways to write a table of squares and cubes: >>> >>> for x in range(1, 11): ... print repr(x).rjust(2), repr(x*x).rjust(3), ... # Note trailing comma on previous line ... print repr(x*x*x).rjust(4) ... 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 1000 >>> for x in range(1,11): ... print '{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x) ... 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 1000
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.