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 is not the name of an air mass?
Rus_ich [418]
<span>All the terms are adjectives, not names of air masses. But among the adjectives, tepid seems to be the odd one out.</span>
5 0
3 years ago
Online Book Merchants offers premium customers 1 free book with every purchase of 5 or more books and offers 2 free books with e
docker41 [41]

Answer:

8/9

Explanation:

i remember this question on my daughters book

8 0
3 years ago
Is C++ a high-level or low-level programming language? What about HTML?
N76 [4]

Answer:

c++ is low level

html high level

Explanation:

6 0
2 years ago
A poem for coduction
Nataly_w [17]
I don't know if you want a poem about conduction but if so here ya go

no matter how the heat
different temperatures meet
hot to cold how it's done
4 0
3 years ago
Read 2 more answers
The reading element punctuation relates to the ability to
Goshia [24]
The ability to pause
3 0
3 years ago
Other questions:
  • Carmina wants to move a paragraph to the right margin of the document she is working in. She moves her cursor to
    8·2 answers
  • There are several different types of RAM, each with its own purpose. Name the three types of RAM and briefly describe their func
    8·2 answers
  • Security and protection as it relates to operating systems is grouped into four categories: Availability, Data integrity, Authen
    9·1 answer
  • I have tried installing "windows media player" on my computer but at a point, something disrupts its instalment or I am asked to
    7·1 answer
  • You are given a class named Clock that has three instance variables: One of type int called hours, another of type boolean calle
    11·1 answer
  • ________________is a distribution of Linux Operating<br>system for desktop computers.<br>​
    15·1 answer
  • Who can help me on my school we will to google meet and i share my screen
    5·1 answer
  • A production house needs an operating system that captures saves and generates information within a specific time. Which type of
    11·1 answer
  • Robert and Anne, a married couple filing jointly, have an adjusted gross income of $68,676. They claim two exemptions, and can d
    15·2 answers
  • Ling has configured a delegate for her calendar and would like to ensure that the delegate is aware of their permissions. Which
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!