Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions