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
List two reasons why “buying a computer is no easy task” ?
ValentinkaMS [17]
The price of it and the quality of it.
6 0
3 years ago
Read 2 more answers
PLEASE ANSWER FAST.one of the barriers for early "talkies" was the need to manually crank the projector and manually synchronize
OleMash [197]

Answer:?

Explanation:?

7 0
3 years ago
The seven basic parts of a computer are
True [87]
Monitor, keyboard, CPU, mouse, and I believe the USB drive , DVD drive and hardware system
4 0
3 years ago
Read 2 more answers
Some Tiny College staff employees are information technology (IT) personnel.
const2013 [10]
xndnxbxnndndndnndnxndnnxndndnndndndnndndndndndnndnxnx
5 0
3 years ago
How to get an hdmi working from a chromebook?
igomit [66]
Use an adapter, costs money though.
8 0
4 years ago
Read 2 more answers
Other questions:
  • Marie uses a browser to visit a blog. What is the unique identifier of the blog?
    13·2 answers
  • For which punctuation symbol will you use the ring finger of your right hand?
    9·1 answer
  • The process of adding a header to the data inherited from the layer above is called what option below
    8·1 answer
  • Operating systems provide a measure of security by allowing users to access to those resources they've been cleared to use as we
    8·1 answer
  • Which would be included in a SaaS platform?<br><br> A.data link<br> B.IaaS<br> C.Java<br> D.vb.net
    5·1 answer
  • There are some processes that need to be executed. Amount of a load that process causes on a server that runs it, is being repre
    7·1 answer
  • List any three importance of computer points​
    8·1 answer
  • Create a query that shows columns employee last name, job title and hire date for those employees who joined the company on or a
    7·1 answer
  • Mha lovers why do other anime lovers report mha lovers for not liking there anime?
    6·2 answers
  • Complete the following sentence by choosing the best answer from the options listed below.
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!