Answer:
The program written in Java is as follows
import java.util.Scanner;
public class mutilate {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int n;
System.out.print("Array Length: ");
n = input.nextInt();
while(n<1 || n > 103) {
System.out.print("Array Length: ");
n = input.nextInt();
}
int a []= new int [n];
int b []= new int [n];
System.out.print("Enter Elements of the Array: ");
for(int i =0;i<n;i++) {
a[i] = input.nextInt();
}
System.out.print("Output: ");
for(int i =0;i<n;i++) {
if(i == 0) {
b[i] = 0+a[i]+a[i+1];
}
else if(i == n-1) {
b[i] = a[i - 1]+a[i]+0;
}
else {
b[i] = a[i - 1]+a[i]+a[i+1];
}
System.out.print(b[i]+" ");
}
}
}
Explanation:
This line allows the program accepts user input
Scanner input = new Scanner(System.in);
This line declares integer n
int n;
The next two line prompts user for length of the array and also accepts input
System.out.print("Array Length: ");
n = input.nextInt();
The following while iteration ensures that the user input is between 1 and 103
while(n<1 || n > 103) {
System.out.print("Array Length: ");
n = input.nextInt();
}
The next two lines declares array a and b
int a []= new int [n];
int b []= new int [n];
The next for iteration allows user enter values for array a
System.out.print("Enter Elements of the Array: ");
for(int i =0;i<n;i++) {
a[i] = input.nextInt();
}
The next for iteration calculates and prints the values for array b based on the instruction in the question
System.out.print("Output: ");
for(int i =0;i<n;i++) {
if(i == 0) {
b[i] = 0+a[i]+a[i+1];
}
else if(i == n-1) {
b[i] = a[i - 1]+a[i]+0;
}
else {
b[i] = a[i - 1]+a[i]+a[i+1];
}
System.out.print(b[i]+" ");
}
What is the quick key to highlighting a column?
Ctrl + down arrow
Ctrl + Shift + down arrow
Right-click + down arrow
Ctrl + Windows + down arrow
The quick key to highlighting a column is the Ctrl + Shift + down arrow. Thus, option (b) is correct.
What is column?The term column refers to how data is organized vertically from top to bottom. Columns are groups of cells that are arranged vertically and run from top to bottom. A column is a group of cells in a table that are vertically aligned. The column is the used in the excel worksheet.
The quick key for highlighting a column is Ctrl + Shift + down arrow. To select downward, press Ctrl-Shift-Down Arrow. To pick anything, use Ctrl-Shift-Right Arrow, then Ctrl-Shift-Down Arrow. In the Move/Highlight Cells, the was employed. The majority of the time, the excel worksheet was used.
As a result, the quick key to highlighting a column is the Ctrl + Shift + down arrow. Therefore, option (b) is correct.
Learn more about the column, here:
https://brainly.com/question/3642260
#SPJ6
Answer:
its (B) ctrl+shift+down arrow
hope this helps <3
Explanation:
An employer plans to pay bonus to each of his employees. Those earning Rs. 2000 or above are to be paid 10 percent of their salary and those earning less than 2000 are to be paid Rs. 200. The input record contains employee number, name and salary of an employee. The output should be employee name and their bonus. Write pseudo code algorithm to process the requirement.
Answer:
vfg
Explanation:
A computer uses a programmable clock in square-wav e mode. If a 500 MHz crystal is used, what should be the value of the holding register to achieve a clock resolution of (a) a millisecond (a clock tick once every millisecond)
Answer:
500,000
Explanation:
A computer uses a programmable clock in square-wave mode. If a 500 MHz crystal is used, what should be the value of the holding register to achieve a clock resolution of (a) a millisecond (a clock tick once every millisecond)
1 millisecond = 1 million second = 1,000,000
For a 500 MHz crystal, Counter decrement = 2
Therefore value of the holding register to a clock resolution of 1,000,000 seconds :
1,000,000/2 = 500,000
what are the morals and ethics of computer
Answer:
Computer ethics is a part of practical philosophy concerned with how computing professionals should make decisions regarding professional and social conduct. Margaret Anne Pierce, a professor in the Department of Mathematics and Computers at Georgia Southern University has categorized the ethical decisions related to computer technology and usage into three primary influences:
The individual's own personal code.
Any informal code of ethical conduct that exists in the work place.
Exposure to formal codes of ethics.
Explanation:
Software that is used to obtain private user information such as a user's keystrokes or copies of e-mail is referred to as: Question 6 options: A) botnet B) adware. C) a backdoor. D) spyware.
Answer:
The correct answer is D) Spyware.
Explanation:
Also known as a Malicious Software (or Malware for short), a Spyware is designed to gain unsolicited entrance into ones computer and when executed, performs the function of illegally stealing one's private information and sending them to the hacker or originator of the software.
The following have been identified as spyware threats:
Transponder (vx2) Hot as HellBlazeFindInternet OptimizerCheers!
Agile Software Development is based on Select one: a. Iterative Development b. Both Incremental and Iterative Development c. Incremental Development d. Linear Development
Answer:
b. Both incremental and iterative development.
Explanation:
Agile software development is based on both incremental and iterative development. It is an iterative method to software delivery in which at the start of a project, software are built incrementally rather than completing and delivering them at once as they near completion.
Incremental development means that various components of the system are developed at different rates and are joined together upon confirmation of completion, while Iterative development means that the team intends to check again components that makes the system with a view to revising and improving on them for optimal performance.
Agile as an approach to software development lay emphasis on incremental delivery(developing system parts at different time), team work, continuous planning and learning, hence encourages rapid and flexible response to change.
The first electric, general-purpose computer, ENIAC, was programmed by calculating algorithms on paper entering code directly into the computer flipping switches by hand using MS-DOS as the operating system
Complete Question:
The first electric, general-purpose computer, ENIAC, was programmed by?
Group of answer choices.
A. Calculating algorithms on paper.
B. Entering code directly into the computer.
C. Flipping switches by hand.
D. Using MS-DOS as the operating system.
Answer:
C. Flipping switches by hand.
Explanation:
The first electric, general-purpose computer, ENIAC, was programmed by flipping switches by hand.
ENIAC is an acronym for Electronic Numerical Integrator and Computer, it was developed in 1945 by John Mauchly and J. Presber Eckert. ENIAC was used for solving numerical problems or calculation-related tasks by the process of reprogramming.
In order to give the ENIAC a series of machine instructions to follow in the execution of a task, the programmers had to undergo the cumbersome procedure of connecting, removing, reconnecting cables and flipping switches by hand because data couldn't be stored in memory.
Which of the following peripheral devices can be used for both input and output? mouse touch screen on a tablet computer printer CPU
Answer:
mouse printer CPU touch screen
Explanation:
on a tablet computer hope this helps you :)
what is programming code
Answer:
Such languages are used to create computer code or program code, the set of instructions forming a computer program which is executed by the computer. This source code is translated into machine code by a compiler or interpreter, so that the computer can execute it to perform its tasks.
Answer:
Writing code,” “coding,” and “programming” are basically interchangeable terms. Broadly speaking, knowing how to write code is the process of creating instructions that tell a computer what to do, and how to do it. Codes are written in various languages, such as javascript, C#, Python, and much more.
hlo samradhiki can we chat in comment section
Determine the median paycheck from the following set:
{$100, $250, $300, $400, $600, $650}
$300
$350
$450
$600
Answer:
My answer to the question is $350.
The middle numbers are $300&$400.
300+400=700/2=350.
Answer:
$350
Explanation:
"The principle of ______________ states that programs tend to access data and instructions nearby recently used data and instructions."
Answer:
Locality of reference.
Explanation:
In computing, The principle of locality of reference is the probability of a processor to repeatedly access the same set of memory locations within a small time interval. This reference of locality can be spatially based (repetitive usage of data within the same location on the computer memory), or temporally based (repetitive usage of a particular data or resources within a shot time interval). The ability of some computing system to perform this action increases their predictability, and efficiency of memory hierarchy use, among other abilities.
All of the following are extra precautions you can take to secure a wireless network EXCEPT ________. change your network name (SSID) enable SSID broadcast turn on security protocols create a passphrase
Answer:
Enable SSID broadcast
Explanation:
All of the following are extra precautions you can take to secure a wireless network except enable SSID broadcast. The correct option is B.
What is SSID broadcast?When people in the area try to join their wireless devices, the name of your network is listed in the list of available networks thanks to broadcasting the SSID.
You can stop SSID broadcasting if you don't want arbitrary wireless devices attempting to connect to your network.
Home networks don't need to have a visible SSID unless they have many access points that devices can switch between.
If your network just has a single router, disabling this function means giving up the ease of adding new home network customers in exchange for certain security gains.
Apart from enabling SSID broadcast, there are other security measures you may take to protect a wireless network.
Thus, the correct option is B.
For more details regarding SSID broadcast, visit:
https://brainly.com/question/13191413
#SPJ6
On the Excel Ribbon, click the Data tab in the Sort & Filter Group, and then click the Sort button to conduct a _____ sort. a. table range b. pivot table c. auto sum d. multiple column
Answer:
a. Table range
Explanation:
Excel is used for maintaining the data of the company. It contains various formulas, features like pivot table, macros, sort & filter group so the firm could able to present its data in an effective and efficient way
Here the sort button is used to ascending or descending the table based on the name, values, etc
So in the given situation, the first option is correct
Answer:
Datasheet, aecending, home
Explanation:
what privacy risks do new technologies present,
and how do we decide if they're worth it?
Answer:
Los riesgos de las nuevas tecnologías se multiplican a medida que nos hacemos dependientes de ellas. También lo hacen a medida que sustituyen a otras formas de contacto social más cercanas
Los riesgos de las nuevas tecnologías son grandes desconocidos. El mal uso de las redes sociales y de Internet en los ordenadores y en el teléfono móvil, entre otros factores, supone un peligro real para todos los estratos de población, pero en especial para los más jóvenes. Pensemos, ¿realmente somos conscientes de los riesgos que suponen las nuevas tecnologías? ¿Sabemos cómo utilizarlas para no ponernos en riesgo?
Cabe destacar que las denominadas nuevas tecnologías de la información y de la comunicación (TICs) son un distintivo de la época actual y se han convertido en herramientas esenciales en las diferentes áreas de la vida. Esto es, para el área académica, laboral, social, de ocio…
En la mayoría de los ámbitos están presentes las TICS, pues incluyen las diferentes herramientas con las que nos manejamos hoy en día: servicios de contacto electrónico (e-mails, servicios de mensajería instantánea, chats), los teléfonos móviles, tablets y ordenadores, las plataformas online de difusión de contenidos, las redes sociales, entre otros..
Explanation:
Where in the Formula tab on the ribbon would you find the Use in Formula function?
Function library
Formula Auditing
Calculation
Defined Names
Answer:
Defined Names
Explanation:
Just did it on Edg 2020
The Formula tab on the ribbon can be found in Defined Names in formula function. The correct option is D.
What is formula tab?The formula tab is where you can insert functions, outline the name, generate the name, review the formula, and so on.
The Formulas tab on the ribbon contains critical and useful functions for creating dynamic reports. Function Library, Defined Names, Formula Auditing, and Calculation are all included.
The Formula tab is where we insert functions, define names, create name ranges, and review formulas. The Formulas tab in the ribbon contains very important and useful functions for creating dynamic reports.
The Formula command is located in the Data group on the Table Tools, Layout tab. When you open a document that contains a formula in Word, the formula automatically updates.
The Formula tab on the ribbon can be found in the formula function's Defined Names.
Thus, the correct option is D.
For more details regarding formula tab, visit:
https://brainly.com/question/20452866
#SPJ5
the property of doing work automatically by the computer
Answer:
Automation
Explanation:
Write Album's PrintSongsShorterThan() to print all the songs from the album shorter than the value of the parameter songDuration. Use Song's PrintSong() to print the songs.
Answer:
Here is the function PrintSongsShorterThan() which prints all the songs from the album shorter than the value of the parameter songDuration.
void Album::PrintSongsShorterThan(int songDuration) const { //function that takes the songDuration as parameter
unsigned int i;
Song currSong; //object of Song
cout << "Songs shorter than " << songDuration << " seconds:" << endl;
for(int i=0; i<albumSongs.size(); i++){
currSong = albumSongs.at(i);
if(currSong.GetDuration()<songDuration){ //checks if the song duration of the song from album is less than the value of songDuration
currSong.PrintSong(); } } } //calls PrintSong method to print all the songs with less than the songDuration
Explanation:
I will explain the working of the for loop in the above function.
The loop has a variable i that is initialized to 0. The loop continues to execute until the value of i exceeds the albumSongs vector size. The albumSongs is a Song type vector and vector works just like a dynamic array to store sequences.
At each iteration the for loop checks if the value of i is less than the size of albumSongs. If it is true then the statement inside the loop body execute. The at() is a vector function that is used to return a reference to the element at i-th position in the albumSongs.
So the album song at the i-th index of albumSongs is assigned to the currSong. This currSong works as an instance. Next the if condition checks if that album song's duration is less than the specified value of songDuration. Here the method GetDuration() is used to return the value of duration of the song. If this condition evaluates to true then the printSong method is called using currSong object. The printSong() method has a statement cout << name << " - " << duration << endl; which prints/displays the name of the song with its duration.
If you see the main() function statement:
musicAlbum.PrintSongsShorterThan(210);
The musicAlbum is the Album object to access the PrintSongsShorterThan(210) The value passed to this method is 210 which means this is the value of the songDuration.
As we know that the parameter of PrintSongsShorterThan method is songDuration. So the duration of each song in albumSongs vector is checked by this function and if the song duration is less than 210 then the name of the song along with its duration is displayed on the output screen.
For example if the album name is Anonymous and the songs name along with their duration are:
ABC 400
XYZ 123
CDE 300
GHI 200
KLM 100
Then the above program displays the following output when the user types "quit" after entering the above information.
Anonymous
Songs shorter than 210 seconds: XYZ - 123
GHI - 200
KLM - 100
Notice that the song name ABC and CDE are not displayed because they exceed the songDuration i.e. 210.
Although slow start with congestion avoidance is an effective technique for coping with congestion, it can result in long recovery times in high-speed networks, as this problem demonstrates.
A) Assume a round-trip delay of 60 msec (about what might occur across the continent) and a link with an available bandwidth of 1 Gbps and a segment size of 576 octets. Determine the window size needed to keep the pipeline full and the a worst case estimate of the time it will take to reach that window size after a timeout occurs on a new connection using Jacobson’s slow start with congestion avoidance approach.
B) Repeat part (a) for a segment size of 16 kbytes.
Answer:
The answer to this question can be defined as follows:
In option A: The answer is "13020".
In option B: The answer is "468 Segments".
Explanation:
Given:
The value of round-trip delay= 60 m-second
The value of Bandwidth= 1Gbps
The value of Segment size = 576 octets
window size =?
Formula:
[tex]\text{Window size =} \frac{(\text{Bandwidth} \times \text{round} - \text{trip time})}{(\text{segment size window })}[/tex]
[tex]=\frac{10^9 \times 0.06}{576 \times 8}\\\\=\frac{10^9 \times6}{576 \times 8\times 100}\\\\=\frac{10^7 \times 1}{96 \times 8}\\\\=\frac{10^7 \times 1}{768}\\\\=13020.83[/tex]
So, the value of the segments is =13020.833 or equal to 13020
Calculating segments in the size of 16 k-bytes:
[tex]\text{Window size} = \frac{10^9 \times 0.06}{16,000 \times 8}[/tex]
[tex]= \frac{10^9 \times 0.06}{16,000 \times 8}\\\\ = \frac{10^9 \times 6}{16,000 \times 8 \times 100}\\\\ = \frac{10^4 \times 3}{16 \times 4}\\\\ = \frac{30000}{64 }\\\\=468.75[/tex]
The size of 16 k-bytes segments is 468.75 which is equal to 468.
When a user runs a program in a text-based environment, such as the command line, what determines the order in which things happen?
Explanation:
In general, when a program runs in text-based environment like command line interface, the program is used for determining the order in which things happen.
As the program runs, the user will not have any choice and he or she can enter the required data.
If the user enters the data in required format then, he/she can get the result or output in desired format.
Discuss the different methods of authentication supported between Microsoft’s Web server (Internet Information Services) and the browsers in common use at your organization. Cover both basic authentication and Microsoft’s challenge-response scheme.
Answer:
Answered below
Explanation:
The Microsoft web server (Internet Information Services) supports the following authentication methods;
1) Basic authentication: This method uses basic authentication to restrict access to files on NTFS-formatted web servers. Access is based on user ID and password.
2) Digest authentication, which uses a challenge-response mechanism where passwords are sent in encrypted formats.
3) Anonymous authentication: In this method, the IIS creates IUSR-computerName account, to authenticate anonymous users.
4) Windows integration uses windows domain accounts for access.
5) .Net passport authentication provides users with security-enhanced access to .Net websites and services.
6) Client certificate mapping where a mapping is created between a certificate and a user account.
Do each of the following in the main function:
a) Write the function prototype for function zero, which takes a double array big_nums and does not return a value.
b) Write the function call for the function in part a.
c) Write the function prototype for function add1AndSum, which takes an integer array one_small and returns an integer.
d) Write the function call for the function described in part c.
Answer:
a)
void zero(double big_nums[]);
b)
zero(big_nums)
c)
int add1AndSum (int one_small[]);
d)
add1AndSum(one_small);
Explanation:
a)
void zero(double big_nums[]);
in this statement:
zero is the name of the function
void is used as the function does not return a value.
The function zero takes an array parameter i.e. big_nums[]
big_nums is the name of the array
big_nums[] array has a data type double
b)
zero is the name of the function
In part a) function zero has a parameter which is the array big_nums. So in order to call this function an array has to be passed as a parameter to this function.
So in this statmenent zero(big_nums) the array big_nums is passed to the zero function. You can also declare a new double type array with a different name in main() function and can pass this to the zero function as:
double array[ ] = { 20.6, 30.8, 5.1};
zero(array);
Look at the following program for the better understanding of part a) and b)
#include <iostream> //for using input output functions
using namespace std; //to access objects like cin cout
void zero (double big_nums[]); // function prototype
int main() { //start of main() function
double a[ ] = { 20.6, 30.8, 5.1}; // double type array a with elements
zero(a); } //calls zero function passing array a to the function
void zero(double big_nums[]){ // function zero with double type array big_nums as parameter and the function returns no value
int i;
for(i=0;i<3;++i) {
cout<<big_nums[i]; } } //prints the elements of array
c)
add1AndSum is the name of the function
int is used as the function does not return an integer.
The function add1AndSum takes an integer array parameter i.e. one_small[]
one_small is the name of the array
one_small[] array has a data type int
d)
add1AndSum is the name of the function
In part c) function add1AndSum has a parameter which is the array one_small. So in order to call this function an array has to be passed as a parameter to this function.
So in this statement add1AndSum(one_small); the array one_small is passed to the add1AndSum function. You can also declare a new int type array with a different name in main() function and can pass this to the add1AndSum function.
A member of the human resources department received the following email message after sending an email containing benefit and tax information to a candidate: Your message has been quarantined for the following policy violation external potential PII.Pls contact the IT security admin for further details. Which of the following BEST describes why this message was received?a. The DLP system flagged the message. b. The mail gateway prevented the message from being sent to personal email addresses c. The company firewall blocked the recipient's IP address. d. The file integrity check failed for the attached files.
Answer:
a. The DLP system flagged the message.
Explanation:
Data Leaked Prevention System is the software that detects potential data breaches that may result in the future. It detects the possible data breach, then monitors it and immediately blocks any sensitive data. DLP system is widely used by businesses. The human resource team received a message because sensitive information about the business benefits and tax is shared with a candidate.
Enum fruit_tag {
BLUEBERRY,
BANANA,
PINEAPPLE,
WATERMELON
};
typedef enum fruit_tag fruit_t;
void printFruit(fruit_t myFruit) {
switch(myFruit) {
case BLUEBERRY:
printf("a blueberry");
break;
case BANANA:
printf("a banana");
break;
case PINEAPPLE:
printf("a pineapple");
break;
case WATERMELON:
printf("a watermelon");
break;
}
}
void compareFruit(fruit_t fruit1, fruit_t fruit2) {
if (fruit1 > fruit2) {
printFruit(fruit1);
printf(" is larger than ");
printFruit(fruit2);
}
else {
printFruit(fruit1);
printf(" is smaller than ");
printFruit(fruit2);
}
}
int main(void) {
fruit_t myFruit = PINEAPPLE;
fruit_t otherFruit = BLUEBERRY;
compareFruit(myFruit, otherFruit);
return 0;
What is the output?
Answer:
The output is "a pineapple is larger than a blueberry ".
Explanation:
In the given C language code Enum, typedef, and two methods "printfruit and compareFruit" is declared, that can be defined as follows:
In the enum "fruit_tag" there are multiple fruit name is declared that use as the datatypes. In the next line, the typedef is defined, that enum to define another datatype that is "fruit_t". In the next step, the printFruit method is defined that accepts "myFruit" variable in its parameter and use the switch case to to check value. In the "compareFruit" method, it accepts two parameters and uses the if-else block to check its parameters value and print its value. In the main method, two variable "myFruit and otherFruit" variable is declared that stores the values and pass into the "compareFruit" method and call the method.Assume the existence of a Phone class. Define a derived class, CameraPhone that contains two data members: an integer named, imageSize, representing the size in megabytes of each picture, and an integer named memorySize, representing the number of megabytes in the camera's memory. There is a constructor that accepts two integer parameters corresponding to the above two data members and which are used to initialize the respective data members. There is also a function named numPictures that returns (as an integer) the number of pictures the camera's memory can hold.
#include <iostream>
using namespace std;
class CameraPhone:Phone{
int imageSize,memorySize;
public:
CameraPhone(int image_size,int memory_size):imageSize(image_size),memorySize(memory_size){}
int numPictures(){
return memorySize-imageSize;
}
}
int main(){}
Here is the code for the derived class, CameraPhone:
class Phone:
def __init__(self, brand, model, price): self.brand = brand self.model = model self.price = priceclass CameraPhone(Phone):
def __init__(self, brand, model, price, imageSize, memorySize): super().__init__(brand, model, price) self.imageSize = imageSize self.memorySize = memorySizedef numPictures(self):
return self.memorySize // self.imageSizeWhat are the derived class?This code defines a derived class, CameraPhone, that inherits from the Phone class. The CameraPhone class has two additional data members: imageSize and memorySize. The constructor for the CameraPhone class takes two additional parameters corresponding to these data members. The numPictures() function returns the number of pictures that the camera's memory can hold.
Here is an example of how to use the CameraPhone class:
phone = CameraPhone("Apple", "iPhone 13 Pro", 1000, 10, 100)
print(phone.numPictures())
# Output: 10
This code will print the number of pictures that the camera's memory can hold, which is 10 in this case.
Find out more on derived class here: https://brainly.com/question/31942927
#SPJ2
Define a function group-by-nondecreasing, which takes in a stream of numbers and outputs a stream of lists, which overall has the same numbers in the same order, but grouped into segments that are non-decreasing.
Answer:
def group_by_nondecreasing( *args ) :
num_list = [arg for arg in args]
sorted_numlist = sorted( num_list )
list_stream = [ sorted_numlist, sorted_numlist, sorted_numlist ]
return list_stream
Explanation:
This python function has the ability to accept multiple and varying amount of arguments. the list comprehension shorten the logical for statement to generate a list of numbers, sorts the list in ascending order by default and duplicates the list in another list.
А.
is the highest education degree available at a community college.
Answer:
The answer is "associate".
Explanation:
The two-year post-school degree is also known as the associate degree, in which the students pursuing any of this degree, which may take as little as 2 years to complete the course, although many prefer to do it at the same rate. Its first two years of a Bachelor (fresh and sophomore years) were covered by an Associate degree.
Which octet of the subnet mask 255.255.255.0 will tell the router the corresponding host ID?The last octetThe first octetThe first and last octetThe middle two octets
Answer:
The last octet
Explanation:
Here in the question, given the sub net mask, we want to know which octet of the subnet mask will tell the router the corresponding host ID.
The correct answer to this is the last octet. It is the last octet that will tell the router the corresponding host ID
why you think Operating System is pivotal in teaching and learning.
Answer:
An Operating System is pivotal in teaching and learning because:
1. It enables computer users to communicate with the hardware.
2. To run any computer programme successfully, the Operating System is basic.
3. It provides a smooth interface for teachers to use video conferencing or other conferencing systems in teaching their students.
4. The OS enables the launching of other learning packages on a computer system.
5. Students can install learning apps on their systems with the help of the OS.
Explanation:
An Operating System is a software which brings about easy communication with the hardware and enablea other programs to run on the computer easily. It provides basic functionality in systems were they are installed.
a reason for giving a Page Quality (PQ) rating of Highest, is it the page has no Ads?
Answer:
quality of highest giving page hash no adds
Define a function readList with one parameter, the (string) name of a file to be read from. The file consists of integers, one per line. The function should return a list of the integers in the file.
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.