asked 48.7k views
3 votes
The objective of this question is to generate and read files that contain a list of random numbers. Write a function that generates a file with following parameters: def fillFile(fileSize, fileName): The function should be called to generate files in the following sizes: fileSizes = 1000,5000,10000,20000,30000,40000,50000] The generated files can have names file 1000 , file5000, file 10000 , file 20000 , fil 30000 , file 40000 , file 50000 .

1 Answer

7 votes

Final answer:

The student is seeking to generate files with random numbers by creating a Python function. The function, fill File, takes the file Size and file Name as parameters. The function is used to create files of different sizes filled with random numbers.

Step-by-step explanation:

The student is asking for help in writing a function that generates files containing a list of random numbers. The function is defined with two parameters: file Size representing the number of random numbers to be written to the file, and file Name representing the name of the file. Below is a sample Python function that performs this task:

import random def fill File(file Size, file Name): with open(file Name, 'w') as f: for _ in range(file Size): f. write(f"{random. randint(1, 100)}\\"). To create files with sizes 1000, 5000, 10000, 20000, 30000, 40000, and 50000, the function can be called like this: file Sizes = [1000, 5000, 10000, 20000, 30000, 40000, 50000] for size in file Sizes: fill File(size, f" file{size}")

answered
User Felipe Santana
by
8.4k points