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]
4 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]4 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
ASAP: Type the correct answer in the box. Spell all words correctly.
DerKrebs [107]

Answer:

has?

Explanation:

i think i need a few more details then we can talk

4 0
3 years ago
How can an attacker execute malware through a script?
Anvisha [2.4K]

Answer:

An attacker can attach a script to a program that you download which then infects your computer.

5 0
2 years ago
Create java program for these 2 question
morpeh [17]

1 see what you can do and go from their

7 0
3 years ago
in a typical e-mail address, the "host" is A. an account designated by a user name B. CPU processor 2500 C. the receiver of an e
NISA [10]
The correct answer is A! :)
5 0
3 years ago
Read 2 more answers
2) Which of the following is a non-routine cognitive skill? A) computer programming skill B) marketing knowledge C) tax accounti
Lilit [14]

Answer:

D. systems thinking ability

Explanation: Cognitive skills are skills required by individuals to process information without showing any mental related issues. Cognitive skills or abilities are closely associated with learning.

Routine cognitive skills are cognitive skills which are regularly applied in processing information mentally.

Non routine cognitive skills are skills that are not regularly utilised in the daily life such as SYSTEM THINKING ABILITY.

3 0
3 years ago
Other questions:
  • Two columns of a relational table can have the same names. <br> a. True <br> b. False
    15·1 answer
  • What is a PowerPoint template?
    6·2 answers
  • For what tools such as USMT and Treanxition used?
    15·1 answer
  • A technician is troubleshooting a printer connected to a computer via USB. The printer will print using the controls at the prin
    9·1 answer
  • If you’re trying to reduce your debt, which of these expenses should you consider cutting out or cutting back on first?
    5·2 answers
  • Write the definition of a function printLarger, which has two int parameters and returns nothing. The function prints the larger
    7·1 answer
  • Submitting a cover letter and resume is a step in the process of applying for a job.
    14·1 answer
  • Multiple Choice
    7·1 answer
  • What are the main dimensions of information systems
    8·1 answer
  • What is the first step of viewing a web page as described in the video?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!