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
Serga [27]
3 years ago
12

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

the sum of all these integers, and stores this sum in a variable name sum.
Computers and Technology
1 answer:
Schach [20]3 years ago
3 0

Answer:

The code is given below with necessary comments for understanding

Explanation:

#Open the input file.

infile = open("numbers.txt", "r")

#Declare and initialize the required variable sum

#to store the sum of integers read from the file.

sum = 0

#Declare and intialize a variable to store the current

#number read from the file in the integer form.

curNum = 0

#Traverse the input file using for loop.

for curLine in infile:

   #Assign the number read from the file to the

   #variable curNum in the integr form.

   curNum = int(curLine)

   #Add the numbers read from the file to the

   #variable sum to get the sum of all the

   #numbers read from the file.

   sum += curNum

# Display the value of the variable runsum.

print(sum)

You might be interested in
How to see where files get ripped to windows?
Artist 52 [7]
File Explorer

AKA: Where to find files
6 0
4 years ago
A small monster collector has captured ten Bagel-type small monsters. Each Bagel-type small monster has a 35% chance of being a
Doss [256]

Answer:

Check the explanation

Explanation:

Each Bagel-type small monster has 0.35 probability of being a Sesame Seed-subtype and 0.2 probability of being a Whole Wheat-subtype.

The probability that exactly 8 of them are Whole Wheat-subtype is \binom{10}{8}(0.2)^8(0.8)^2 using multiplication principle, because first need to choose which 8 are Whole Wheat-subtype, and if exactly 8 of them are Whole Wheat-subtype, then other two are not Whole Wheat-subtype. The former has probability 0.2, while the latter has probability 1-0.2 = 0.8 .

Kindly check the attached images below for the complete answer to the question above

6 0
3 years ago
When the animation and the graphic designs are used to sell products or services, it is known as multimedia advertising. The sta
Aliun [14]

\qquad \qquad\huge \underline{\boxed{\sf Answer}}

The Correct choice is " True "

When the animation and the graphic designs are used to sell products or services, it is known as multimedia advertising.

3 0
3 years ago
2 why do we use the binary number system to store information on a computer
shusha [124]
Depending on the type of computer, we don't use binary. Analog and mechanical computers can express more than two values.

The electronic computers that we commonly use are electronic digital computers. Digital computers use binary. That way it's simple, if there's no voltage that's considered logical 0. If there is voltage it's considered logical 1.
4 0
3 years ago
Consider the following code:
ICE Princess25 [194]

Answer: 3

Explanation:

Because X = 18 and our condition given to the code if > and < which do not match with the input so it prints 3.

4 0
3 years ago
Other questions:
  • The ____ is a single user, nonportable computer designed to perform engineering, cad, and software development work.
    9·1 answer
  • QUESTION 7 of 10: A surplus can be best defined as:
    10·1 answer
  • What browser is included with windows?
    7·1 answer
  • Describe a way in which a badly-designed or badly-constructed STRUCTURAL subsystem might impact the PROPULSION subsystem.
    5·1 answer
  • The mouse pointer becomes different shapes depending on the pointer s location and locations you click on the screen. true false
    6·1 answer
  • A(n) ___________ operating system provides process and memory management services that allow two or more tasks, jobs, or program
    6·1 answer
  • What is the safest way to pay online​
    13·2 answers
  • I have a variable and set it equal to 5. 1 then send it as an argument to a function that adds 5 to the variable passed in. Outs
    9·1 answer
  • Explain why this scenario could put an organization in jeopardy of losing some of its workforce.
    12·1 answer
  • Which of the following will you do in step X in the following series of clicks to change the bounds of
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!