Question: Define a method / function randoms _ to _ file ( n , n 1 , n 2 , filename ) such that n random

Define a method/function randoms_to_file(n, n1, n2, filename) such that n random
integers (positive or negative) in the range of [n1, n2] are generated and will be written
to the file with the name of filename.
Define a method/function read_file_and_process() such that:
o Prompt for a filename of file to be opened for inputs, you need to use while-loop
with try-except in case of the incorrect input of the file name.
o Read in all the numbers on the file (hints: you can only read in a string, so you
need to use int() for conversion to integers).
o A list of items is returned with items in this order in the list:
The minimum number in the file
The maximum number in the file
The number of integers in the file
The average of those numbers in the file
(Hints: The largest integer is sys.maxsize, the smallest is -sys.maxsize-
1)
Implement a regular main() function such that:
o Prompt for inputs of n, n1, n2, filenamesee the above definitions for them. A
while-loop with try-except is required to make sure of the correct inputs!
2
o Call function randoms_to_file(....)
o Call function read_file_and_process()
o Print the outputs (returned from the above call)
o (Hints: use the following demo execution samples to guide your design and
implementation of this project.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!