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
Helen [10]
3 years ago
5

The function below tries to create a list of integers by reading them from a file. The file is expected to have a single integer

per line and the code works correctly in that case. If any of the lines don't contain just an integer, than this code fails. Fix this code so that it ignores any lines that don't contain integers instead of raising an exception. Do this with try/except blocks. Your code should still return the list of integers from the lines that contain integers.

Computers and Technology
1 answer:
Setler [38]3 years ago
4 0

Answer:

Check the explanation

Explanation:

def get_list_of_integers_from_file(filename):

int_list=[]

for line in open(filename).readlines():

try:

int_list.append(int(line))

except:

continue

return int_list

print(get_list_of_integers_from_file('file.txt'))

 

File.txt:

Kindly check the output below.

You might be interested in
Which of the following statements is true for DMA: (only one correct answer) A. In DMA, Processor checks status until the operat
Ronch [10]

Answer:

<u>D. In DMA, interrupt is sent when the task is completed</u>

Explanation:

Note, the term Direct Memory Access simply refers to a computer feature that allows hardware subsystems to directly access the main system memory of a computer, without any the aid of the central processing unit (CPU).

It is a fact that while the transfer process is ongoing, an interrupt (interrupt signal) is not sent until when the task is completed.

6 0
3 years ago
What should be a technicians first step in an A/C system
hram777 [196]
A technician's first step with an A/C system is to perform visual inspection
8 0
3 years ago
What are seven main internal parts of a computer
Alexandra [31]
The hard drive
the power supply
the ram
the heat sink
the cpu
the motherboard
expansion slots
6 0
3 years ago
Read 2 more answers
Give three general reasons for the importance of computer networking.
LiRa [457]
I think the First reason is; it provides the best way of business communication.
Second reason, streamline communication
Third reason cost effective resource sharing :) (hope this helps)
5 0
2 years ago
Three variables, x, y and z, supposedly hold strings of digits, suitable for converting to integers. Write code that converts th
Gelneren [198K]
The answer is 45boobg
3 0
3 years ago
Read 2 more answers
Other questions:
  • 9. The best way to insert an existing Excel chart into a document is to A. use the Object command. B. click the Insert tab and c
    6·2 answers
  • Which one of these do not belong on the Do's list in Helpful Hints when preparing a presentation: Which one of these do not belo
    8·1 answer
  • A friend is having a problem with keeping a fish tank at the right temperature so the fish stay healthy. Describe how you could
    9·1 answer
  • What is the keyboard shortcut used to paste previously copied text?
    15·2 answers
  • The Windows Remote Desktop Web connection that allows users to connect to a work or home computer and access files is considered
    7·2 answers
  • What would be used by a business to assess how the business is working within its organization goals? O A. Information systems B
    8·1 answer
  • In the computer science industry, the process of finding and removing errors from computer hardware or software is known as
    7·1 answer
  • Identify a characteristic that is a disadvantage of cloud-based hosting.
    11·1 answer
  • 4. The volume of a sphere is (4.0/3.0)rr3 and the surface area is 4.0rr2, where r is the radius of
    12·1 answer
  • write a function named get majority last name that accepts as its parameter a dictionary from strings to strings the keys of the
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!