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
2. The Internet could best be described as: *
Ber [7]

Answer:

Explanation:

All options are correct.

6 0
3 years ago
Raid level 6 is basically the same as RAID level 5, but it adds a second set of parity bits for added fault tolerance and allows
Leviafan [203]

Answer:

True

Explanation:

3 0
4 years ago
What does VERONIcA stand for?
kompoz [17]
Very Easy Rodent-Oriented Netwide Index to Computerized Archives
5 0
4 years ago
Read 2 more answers
To find all the prime numbers less than or equal to a given integer n by Eratosthenes' method: 1. Create a list of consecutive i
natta225 [31]

Answer:

I am writing a Python program:

def Eratosthenes(n):  

   primeNo = [True for i in range(n+1)]  # this is a boolean array

   p = 2  # the first prime number is initialized as 2

   while (p * p <= n):     # enumerates all multiples of p

       if (primeNo[p] == True):                

           for i in range(p * p, n+1, p):  #update multiples

               primeNo[i] = False

       p = p + 1        

   for p in range(2, n):   #display all the prime numbers

       if primeNo[p]:  

           print(p),    

def main():     #to take value of n from user and display prime numbers #less than or equal to n by calling Eratosthenes method

   n= int(input("Enter an integer n: "))

   print("The prime numbers less than or equal to",n, "are: ")  

   Eratosthenes(n)      

main()      

Explanation:

The program contains a Boolean type array primeNo that is initialized by True which means that any value i in prime array will be true if i is a prime otherwise it will be false. The while loop keeps enumerating all multiples of p starting from 2, and striking them off from the original array list and for loops keep updating the multiples. This process will continue till the p is greater than n.  The last for loop displays all the prime numbers less than or equal to n which is input by user. main() function prompts user to enter the value of integer n and then calls Eratosthenes() function to print all the prime numbers less than or equal to a given integer n.

   

7 0
3 years ago
How is hyper tension, heart disease, and strokes related?
amid [387]
Hypertension, heart disease, and stroke are related by the process of atherosclerosis. Atherosclerosis refers to the build-up and accumulation of fatty substances (also known as plaque) in the inner walls of the arteries. Atherosclerosis can lead to hypertension, heart disease, and strokes.
5 0
3 years ago
Other questions:
  • A bit shift is a procedure whereby the bits in a bit string are moved to the left or to the right. For example, we can shift the
    12·1 answer
  • Need Help ASAP!
    14·2 answers
  • Why is it important to use standard english when applying for a job
    13·2 answers
  • Irena sends unwanted e-mails to another girl in her class, but she is reported to the principal. Irena stops sending the e-mails
    12·2 answers
  • The GeForce GTX 1060 graphics card requires 120 W of power. You plan to install it in a PCIe 3.0 ×16 slot. Will you need to also
    13·1 answer
  • Alice is working in a database containing the names, service locations, and services offered by landscapers. She needs to find l
    12·1 answer
  • landon starts his computer and gets message, hard drive is not found. He was watching a movie the previous night, what might the
    6·1 answer
  • The math club starts with 5 members. Five months later, their membership has grown to 50 members.
    5·2 answers
  • Is it bad to leave your laptop plugged in all the time
    13·1 answer
  • _______ is the use of software to assist in the creation, analysis, and modification of the design of a component or product.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!