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
elena-s [515]
4 years ago
10

Define a function readList with one parameter, the (string) name of a file to be read from. The file consists of integers, one p

er line. The function should return a list of the integers in the file.

Computers and Technology
1 answer:
steposvetlana [31]4 years ago
4 0

Answer:

Here is the Python function readList:

def readList(filename):  #function definition of readList that takes a filename as a parameter and returns a list of integers in the file

   list = []  # declares an empty list

   with open(filename, 'r') as infile:  # opens the file in read mode by an object infile

       lines = infile.readlines()  # returns a list with each line in file as a list item

       for line in lines:   #loops through the list of each line

           i = line[:-1]  # removes new line break which is the last character of the list of line

           list.append(i)  # add each list item i.e. integers in the list

       return list  #returns the list of integers

#in order to check the working of the above function use the following function call and print statement to print the result on output screen

print(readList("file.txt")) #calls readList function by passing a file name to it

Explanation:

The program is well explained in the comments mentioned with each line of the code.

The program declares an empty list.

Then it opens the input file in read mode using the object infile.

Next it uses readLines method which returns a list with each line of the file as a list item.

Next the for loop iterates through each item of the file which is basically integer one per line

It adds each item of list i.e. each integers in a line to a list using append() method.

Then the function returns the list which is the list of integers in the file.

The program along with it output is attached. The file "file.txt" contains integers 1 to 8 one per line.

You might be interested in
Is a house phone a computer?<br> And why??
aev [14]

Answer:

yes because they emit radio waves or radio frequency

Explanation:

8 0
3 years ago
Read 2 more answers
Luis is cloud-based( microsoft bot framework). true false
zhenek [66]

True

Language Understanding Intelligence Service (LUIS) is a cloud-based API service and is one of the many Cognitive Services provided by Microsoft. LUIS applies custom machine-learning intelligence to a user’s natural language text to predict overall meaning and pull out detailed and relevant information. Using LUIS, we can use REST APIs to extract important information like phrases from any sentence.


5 0
4 years ago
Read 2 more answers
Six external parts or periphersal of a computer system
BARSIC [14]


1.) Keyboard

2.) Mouse

3.) monitor

4.) printers

5.) speakers

6.) microphone

3 0
4 years ago
A store manager is looking at inventory and decides it is time order swim suits because the spring time is approaching. This is
Fudgin [204]

Swimsuit Trends Taking Over Instagram ... taking a careful look at our current bathing suit inventory. ... or you're just looking for some quality lounge chair time, ...

3 0
4 years ago
Complete the function to return the factorial of the parameter using recursion.
Klio2033 [76]

def recursiveFactorial(number):

   if number > 1:

       return number * recursiveFactorial(number-1)

   else:

       return 1

stringNum = input("Enter a positive integer: ")

num = int(stringNum)

print(recursiveFactorial(num))

7 0
3 years ago
Other questions:
  • What is the mass of the light bulb? a. 425.6 g b. 204.6 g c. 240.56 g d. 245.6 g
    6·2 answers
  • Which of the following is a disadvantage of using open source software?
    14·1 answer
  • To properly insert a memory module, you must locate the direction of the ______ .
    14·1 answer
  • What does it mean to design,<br> implement, and maintain computer<br> systems?
    15·1 answer
  • Word processing software programs can run on smartphones.<br> True<br> Or <br> False
    6·1 answer
  • Print 1 to 100 in visual basic .6
    10·1 answer
  • What is the value of the variable index after the Python code below is executed? word = 'bAnana' index = word.find('a')
    10·1 answer
  • Question # 2 Multiple Select You wrote a program to compare the portion of drivers who were on the phone. Which statements are t
    15·1 answer
  • You compared each letter in the correct word to the letter guessed.
    5·1 answer
  • The lost boy gave the correct
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!