Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

36. Write a MARIE subroutine to subtract two numbers.

Answered: 1 week ago

Question

3. Identify the refusal of the call in Star Wars.

Answered: 1 week ago