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
Your computer running Windows 7 is doing some very strange things with the operating system. You are fairly certain it is not a
IrinaVladis [17]

A scan/ digost scan? im not sure but normaly when ever my coumputer acts up i run a scan


7 0
3 years ago
For Excel:
Tom [10]
I'm not sure what the 'following formats' are, but simply putting a $ in front of the letter will lock the column reference, and putting a $ in front of the number will lock the row reference. Putting a $ in front of both will allow you to keep the cell reference the same. For example:
A1 should be A$1$ in an equation to keep the reference as A1 for all 'filled down' equations.
3 0
3 years ago
What is the line tool used for in photoshop
ale4655 [162]
Creates line<span> shapes and paths.</span>
5 0
3 years ago
You have a farm in the mountains. It is difficult for the power supply company to provide electricity at hilly areas. The area i
White raven [17]
D . a wind turbine power plant .
3 0
4 years ago
In Excel, by default, text is ____ in a cell.
Elanso [62]
<span>In excel, by default, the text is Left-alligned in a cell.
Usually, the text really is in left-aligned even in word documents. 
It's up to the user's preference to change the alignment of the text or do changes in any design.</span>
8 0
4 years ago
Other questions:
  • Need help with this C++ question
    5·1 answer
  • Which of the following might be ways to reduce cognitive overload? Select all that apply
    5·1 answer
  • QUESTION 8 Software applications that generate information are located in the first tier of n-tier architectures. True False
    7·1 answer
  • The Start menu on Windows computers changes based on actions performed by their users. True False
    15·2 answers
  • A corporation needs an operating system that allows the various teams in its office to network and collaborate on projects. Whic
    13·2 answers
  • Please, Help me with this question, I tried it but It always says #Value.
    5·1 answer
  • "The ______ of an operational system that supports an organization includes policies, requirements, and conditional statements t
    13·1 answer
  • One shortcoming of rapid application development (RAD) is _____.
    9·1 answer
  • What is the Purpose and function of the Global Positioning System (GPS)?
    7·1 answer
  • Explain Text align , Text Decoration, colour, Text shadow..​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!