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
Drivers must always yield to emergency vehicles traveling
alina1380 [7]

True. Drivers must always yield to emergency vehicles traveling. Emergency vehicles always have the right of way, and other cars on the road need move out of their way when they see them driving with their hazards on. If there are no emergency lights or sirens, then it is okay to treat these vehicles like another vehicle on the road.

4 0
3 years ago
Write the code to compute and output how many times the value 99 is found in an array of integers named numbers
astraxan [27]
Thank you for being the rare question where you actually provide what language you want your answer in; I approve, and encourage this.

In Java, the following will work.
I made it a bit more versatile to work with others numbers, other than 99, if you so please (if not, just hardcode the 99 in yourself).

// Example list - fill this with numbers yourself.
ArrayList<Integer> nums = new ArrayList<>();
int n = 99;
int count = (int)nums.stream().filter(i -> i == n).count();
System.out.println(n + " occurences.");
8 0
4 years ago
Create a program that compares the unit prices for two sizes of laundry detergent sold at a grocery store.
astraxan [27]

Complete Question:

Create a program that compares the unit prices for two sizes of laundry detergent sold at a grocery store. Console Price Comparison Price of 64 oz size: 5.99 Price of 32 oz size: 3.50 Price per oz (64 oz): 0.09 Price per oz (32 oz): 0.11

Using Python

Answer:

<em>This program does not make use of comments (See explanation section)</em>

price64 = float(input("Price of 64 oz size: "))

price32 = float(input("Price of 32 oz size: "))

unit64 = price64/64

unit32 = price32/32

print("Unit price of 64 oz size: ", round(unit64,2))

print("Unit price of 32 oz size: ", round(unit32,2))

if unit64>unit32:

     print("Unit price of 64 oz is greater" )

else:

     print("Unit price of 32 oz is greater" )

Explanation:

This line prompts the user for the price of 64 oz size

price64 = float(input("Price of 64 oz size: "))

This line prompts the user for the price of 32 oz size

price32 = float(input("Price of 32 oz size: "))

This line calculates the unit price of 64 oz size

unit64 = price64/64

This line calculates the unit price of 32 oz size

unit32 = price32/32

This next two lines print the unit prices of both sizes

print("Unit price of 64 oz size: ", round(unit64,2))

print("Unit price of 32 oz size: ", round(unit32,2))

The next line compares the unit prices of both sizes

if unit64>unit32:

This line is executed if the unit price of 64 oz is greater than 32 oz

     print("Unit price of 64 oz is greater" )

else:

This line is executed, if otherwise

     print("Unit price of 32 oz is greater" )

4 0
3 years ago
Which of the following is the best example of a manager with a delegator leadership style
monitta
No examples posted but here are a few examples;
Boss will send other employees to meetings in his/her place
Boss will leave other employees in. Charge when he/she is not there for a period of time.
Boss will assign special assignments
5 0
4 years ago
Read 2 more answers
In the event that a software product fails within a predetermined. Clients use a​
Musya8 [376]

Answer:

try to update product software it will working

Explanation:add license product of a software

5 0
4 years ago
Other questions:
  • What are three methods of sustainable farming and describe each.
    9·1 answer
  • In normal view, powerpoint's ________ contains buttons such as notes, comments, and view.
    14·1 answer
  • To create a new table by using a select statement, you code the ___________________________ clause.
    14·1 answer
  • Which popular file format loses some of the information from the image? JPEG TIFF RAW NEF
    12·1 answer
  • What is the initial page of the website​
    9·1 answer
  • Macro mode is used to take landscape photographs of subjects fairly far from the camera.
    12·2 answers
  • Please help coding assignments i will give brainliest :)
    6·1 answer
  • Who is known as the first computer programmer?​
    13·1 answer
  • State five differences between selecting and highlighting ​
    7·1 answer
  • Why does a computer need an operating system?<br><br> ​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!