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 friend Aria is complaining that programming seems too complicated. She says, “Why do we need things like sequence, selectio
GaryK [48]

Answer: A sequence is a basic algorithm. A set of logical steps is carried out in order. A Selection and coding is the section of code that is only carried out if the conditions are met. A iteration is A line of code that is being repeated until the desired results has come out. A variable is a value that can change when the condition is changed your information passed through the program.

Explanation:

5 0
3 years ago
You have just starting working at Quantum Company. As a new programmer, you have been asked to review and correct various pseudo
Alecsey [184]

Answer:

The correct answer to the following question:

while sub < SIZE AND foundIt = "N"

Explanation:

Firstly, we start the pseudocode after that set the variable sub to 0 and size to 1 of num type and also set a num type array VALID_ITEM[5] and its elements are 27,53,84,89,95.

Than set string type variable foundIt to "N", then we set a while loop and correct its condition is "< SIZE AND foundIt = "N" ".

Than starts if condition which is "item = VALID_ITEM[sub]", if the condition is true than foundIt = "Y", after that endif.

Than increment the variable sub, after that endwhile, after this, we start if condition which is "foundIt = "Y" " if the condition is true then output "Valid item number" or else "Invalid item number", and then we endif and after all stop the pseudocode.

8 0
4 years ago
___________ is produced by propulsion systems or engines.
Rama09 [41]
I think it’s thrust good luck
8 0
4 years ago
Consider the code block below. What is the value of amount when this method is called twice, the first time using cookieJar(7) a
RUDIKE [14]

Answer:

C. 22

Explanation:

Given that the argument is being passed by value, there is no memory to consider.  So cookieJar(7) returns 7 and cookieJar(22) returns 22.

If the argument parameter was passed by reference or pointer, then perhaps the value from cookieJar(7) would be considered with cookieJar(22).

Note, this code block really isn't doing anything other than returning the value passed into it.  The "amount" variable is immediately set to 0, and then the value passed in is added to amount (which is 0), and returns.  The following code could replace this function:

public static int cookieJar(int addCookies){

return addCookies;

}

The above code will return an equivalent output to the given code.

Notice, the function is not dependent on any previous call, so the value for each is unique to the call itself, i.e., cookieJar(22) returns 22 and cookieJar(7) returns 7.

So, C. 22 would be correct.

3 0
3 years ago
When should you close the socket python tcp server client.
Aleksandr-060686 [28]
F socket refers to an open TCP connection, the connection is closed. If a stream socket is closed when there is input data queued, the TCP connection is reset rather than being cleanly closed. The descriptor of the socket to be closed

To close the socket you need to call shutdown() first and then close(), and shutdown takes an argument
4 0
3 years ago
Other questions:
  • A company wishes to move all of its services and applications to a cloud provider but wants to maintain full control of the depl
    7·1 answer
  • Customer A with a Bronze service level package calls in a Critical System Failure at 9:00 AM. Customer B with a Silver service l
    15·1 answer
  • A delimiter is used to do which of these? A. Separate two lines of data from each other. B. Separate two fields within a line of
    9·2 answers
  • What is the formula that calculates the session fee for members in excel
    13·1 answer
  • java Consider a class MotorBoat that represents motorboats. A motorboat has attributes for: The capacity of the fuel tank The am
    15·1 answer
  • Select the correct statement(s) regarding CENTREX. a. CENTREX systems reside at the service providers central office, however, t
    11·1 answer
  • When do you use FTP?
    10·2 answers
  • Anybody know this question???
    6·1 answer
  • PLZ PLZ PLZ PLZ HELP I ONLY HAVE 5 MINUTES IT SAYS THE SUBJECT IS COMPUTERS AND TECHNOLOGY BUT ITS ACTUALLY MEDIA LIT
    5·1 answer
  • Difference between multi-national and global company​
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!