1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tester [92]
3 years ago
9

A file named numbers.txt contains an unknown number of lines, each consisting of a single positive integer. Write some code that

reads through the file, ignoring those value that are not bigger than the maximum value read up to that point. The numbers that are NOT ignored are added, and their sum stored in a variable called runsum.
Computers and Technology
1 answer:
Reptile [31]3 years ago
8 0

Answer:

  1. with(open("numbers.txt")) as file:
  2.    data = file.readlines()  
  3.    runsum = 0
  4.    largest = 0
  5.    
  6.    for x in data:
  7.        if(int(x) > largest):
  8.            largest = int(x)
  9.            runsum += largest  
  10.    
  11.    print(runsum)

Explanation:

The solution code is written in Python 3.

Firstly, open a filestream for numbers.txt (Line 1) and then use readlines method to get every row of data from the text files (Line 2).

Create a variable runsum to hold the running sum of number bigger than the maximum value read up to that iteration in a for loop (Line 3).

Use a for loop to traverse through the read data and then check if the current row of integer is bigger than the maximum value up to that point, set the current integer to largest variable and then add the largest to runsum (Line 6 - 9).

At last display the runsum to console terminal (Line 11).

You might be interested in
What kind of information can be found in a ROM:
tester [92]
The answer is C, ROM often stores the basic instructions a computer needs when powering on, part if the BIOS.
3 0
3 years ago
What is the distinction between a network and an internet?
kompoz [17]
Hi,

Network: Is group of computers connected together via communications devices and transmission media.

Internet: Is a worldwide collection of networks that connect Governments, Businesses, Institutions and Individuals thought their personal devices.

Hope this helps.

r3t40
8 0
3 years ago
How can ICTs be used in the workplace to improve the way employees
nadezda [96]

Answer:

it allows them to work more efficiently, with fewer waisted resources

Explanation:

3 0
2 years ago
In full verbatim, a person wants to say that they admitted him to a hospital last month. He makes a mistake about the date and q
MA_775_DIABLO [31]
He should cancel the date and move to another country semis how he screwed up his work, hope this helped
3 0
2 years ago
Advantages of using networks include all of these except for a. sharing data and info b. sharing software c. sharing passwords d
skelet666 [1.2K]

Answer:

C

Explanation:

Because they don't want you to share your password

7 0
3 years ago
Other questions:
  • Which of the following is a beneficial reason to extract mineral resources from the earth?
    13·2 answers
  • After Maya gave her friend the password to a protected website, the friend was able to remember it only long enough to type it i
    6·1 answer
  • what notation system supports presenting the largest numbers using fewest digits; Binary, decimal or hexadecimal?
    11·1 answer
  • You work as the IT administrator for a small corporate network. To accommodate specific network communication needs for an upcom
    9·1 answer
  • Why is charles babbage known as father of computer?​
    10·1 answer
  • 1) ( IBADE - 2020)A legislação que regula o uso da Internet no Brasil por meio da previsão de princípios, garantias, direitos e
    9·1 answer
  • Why computer manufacturers constantly releasing faster computers ?
    14·1 answer
  • Identify the following​
    9·1 answer
  • When you call a method with a parameter list, the arguments in the argument list Select one: a. must be coded in the same sequen
    15·1 answer
  • How many pages is 1500 words double spaced 12 font?.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!