Question: 12a. floor_and_ceiling.py Write a program that writes an output file that has the same contents as the input file with the following modifications: If an
12a. floor_and_ceiling.py
Write a program that writes an output file that has the same contents as the input file with the following modifications:
- If an integer in the input file is less than 5, replace it with 5
- If an integer in the input file is greater than 10, replace it with 10
The input file should a text file containing integers separated by spaces
input_numbers.txt
1 2 3 4 5 19 11 10 18 13 3 16 9 8 11 For example:
python floor_and_ceiling.py input_numbers.txt output_numbers.txt Would write the file:
output_numbers.txt
5 5 5 5 5 10 10 10 10 10 5 10 9 8 10 TIP
To convert a list of numbers to a string, you can use the function list_of_numbers_to_string found in helpful.py. list_of_numbers_to_string takes a list of strings as its input.
Given the following script named example.py:
from helpful import list_of_numbers_to_string numbers = ['1', '2', '3', '4'] numbers_as_string = list_of_numbers_to_string(numbers) print(numbers_as_string) Running python example.py will print:
1 2 3 4 12b. greater_than_one_hundred.py
Write a program that writes an output file that has the same contents as the input file but every line that sums to greater than 100 is removed.
input_numbers.txt
30 30 30 30 10 10 10 10 10 5 5 5 40 40 40 1 2 3 4 5 55 55 For example:
python greater_than_one_hundred.py input_numbers.txt output_numbers.txt Would write the file: output_numbers.txt
10 10 10 10 10 5 5 5 1 2 3 4 5 12c. less_than_ten_words.py
Write a program that writes an output file that has the same contents as the input file but every line that has less than ten words is removed.
input_file.txt
one two three four five six even eight nine ten eleven one two three four five six one two three one two three four five six even eight nine ten eleven twelve thirteen one two three four five six For example:
python less_than_ten_words input_file.txt output_file.txt Would write the file: output_file.txt
one two three four five six even eight nine ten eleven one two three four five six even eight nine ten eleven twelve thirteen Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
