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
Which code snippet could be used to print the following series?
GaryK [48]
C is the answer, I think
7 0
1 year ago
Three reasons why users attach speakers to their computers.
ZanzabumX [31]

Answer:

Iv'e answered this question 2 times already lol. The purpose of speakers is to produce audio output that can be heard by the listener. Speakers are transducers that convert electromagnetic waves into sound waves. The speakers receive audio input from a device such as a computer or an audio receiver.

Explanation: I hope this helps!

8 0
3 years ago
In the CPT manual, the digits of the Category III codes are not intended to reflect the placement of the code in the Category I
dexar [7]

Answer:

Nomenclature

Explanation:

In the CPT manual, the digits of the Category III codes are not intended to reflect the placement of the code in the Category I section of the CPT Nomenclature .

3 0
3 years ago
The internet is an accurate and reliable source of information and an investigator should take the information at face value. tr
AVprozaik [17]
False

Not everything is true, face value is not always reliable
7 0
3 years ago
What is reference file​
Ratling [72]

Answer:

A reference file is mainly used for reference or look-up purposes. Look-up information is that information that is stored in a separate file but is required during processing.

Explanation:

Hope this helps ;)

8 0
3 years ago
Read 2 more answers
Other questions:
  • How can you different between standard and protocol?
    15·1 answer
  • Which amendment discussed in the unit do you think has the greatest effect on your life? Why?
    14·1 answer
  • All of the following are the four more widely social media networks discussed in the text EXCEPT:
    11·2 answers
  • Rita wants to know the size of each image in a folder. Which view will help her find this information quickly?
    7·1 answer
  • Which statement best describes the cut and paste option in a word processor?
    6·2 answers
  • For this lab, you will work on a simple GUI application. The starting point for your work consists of four files (TextCollage, D
    5·1 answer
  • Which type of styles can be applied to a word, phrase, or sentence?
    7·1 answer
  • What is the Piston Displacement having 3-inch bore and 3-inch stroke?
    11·1 answer
  • Which activity is the best example of a negative habit that may result from
    12·1 answer
  • Write the simplest statement that prints the following: 3 2 1 Go! python
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!