Python_Programming_Week7
1. Write a Python program “Lab7B.py” to complete the following: • 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 “ze”, the smallest is “-ze1”) • Implement a regular main() function such that: o Prompt for inputs of n, n1, n2, filename—see the above definitions for them. A while-loop with try-except is required to make sure of the correct inputs! 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.)
Escuela, estudio y materia
- Institución
- Python Programming
- Grado
- Python Programming
Información del documento
- Subido en
- 22 de julio de 2023
- Número de páginas
- 3
- Escrito en
- 2022/2023
- Tipo
- Examen
- Contiene
- Preguntas y respuestas
Temas
-
pythonprogrammingweek7
Documento también disponible en un lote