Question: 12d. replace_with_fraction.py Write a program that writes an output file that has the same contents as the input file but each integer in the input
12d. replace_with_fraction.py
Write a program that writes an output file that has the same contents as the input file but each integer in the input file is divided by the sum of the integers in its line.
numbers.txt
5 5 5 5 5 5 15 4 4 4 4 For example:
python replace_with_fraction numbers.txt fractions.txt Would write the file: fractions.txt
0.2 0.2 0.2 0.2 0.2 0.25 0.75 0.25 0.25 0.25 0.25 Note: The decimals in each line will add up to one.
12e. smallest_largest.py
Write a program that writes an output file that has the same contents as the input file with the following modifications.
For each line:
- Subtract the smallest number in the line from every number in the line
- Divide each number in the line by the maximum number in the line
- Print the resulting list of numbers to the output file with a space between each number
input.txt
5 15 15 20 2 4 8 4 2 4 For example:
python smallest_largest.py input.txt output.txt Would write the file: output.txt
0.0 0.5 0.5 0.75 0.0 0.25 0.75 0.25 0.0 0.5 Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
