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
KatRina [158]
3 years ago
10

Write a function that accepts a list as an argument (assume the list contains integers) and returns the total of the values in t

he list.
Computers and Technology
1 answer:
Serga [27]3 years ago
8 0

Answer:

def listSum(mylist):

   sum =0

   for item in range(0,len(mylist)):

       sum=sum+mylist[item]

   print(sum)

Explanation:

Using the Python programming language, I defined a function as listSum that accepts a list as a parameter and returns the sum of the elements in the list.

The most important logic here is defining the range of elements in the list not to exceed the length of the list using the len function. Then using a for statement, we loop through each element and add them up to a sum variable initially assigned the value of 0.

You might be interested in
Although females are born with approximately 2 million ova, this number declines to
Pepsi [2]

Answer: 1

Explanation:

a woman is born with about 1-2million ova, during puberty this figure reduce to between 600,000 and 1million. during her child bearing years the figure drops down to about 300,000 to 400,000 ova, out of which only about 500 would be ovulated during her reproductive years. the rest die out during menopause.

8 0
3 years ago
and assuming main memory is initially unloaded, show the page faulting behavior using the following page replacement policies. h
Svet_ta [14]

FIFO

// C++ implementation of FIFO page replacement

// in Operating Systems.

#include<bits/stdc++.h>

using namespace std;

// Function to find page faults using FIFO

int pageFaults(int pages[], int n, int capacity)

{

   // To represent set of current pages. We use

   // an unordered_set so that we quickly check

   // if a page is present in set or not

   unordered_set<int> s;

   // To store the pages in FIFO manner

   queue<int> indexes;

   // Start from initial page

   int page_faults = 0;

   for (int i=0; i<n; i++)

   {

       // Check if the set can hold more pages

       if (s.size() < capacity)

       {

           // Insert it into set if not present

           // already which represents page fault

           if (s.find(pages[i])==s.end())

           {

               // Insert the current page into the set

               s.insert(pages[i]);

               // increment page fault

               page_faults++;

               // Push the current page into the queue

               indexes.push(pages[i]);

           }

       }

       // If the set is full then need to perform FIFO

       // i.e. remove the first page of the queue from

       // set and queue both and insert the current page

       else

       {

           // Check if current page is not already

           // present in the set

           if (s.find(pages[i]) == s.end())

           {

               // Store the first page in the

               // queue to be used to find and

               // erase the page from the set

               int val = indexes.front();

               

               // Pop the first page from the queue

               indexes.pop();

               // Remove the indexes page from the set

               s.erase(val);

               // insert the current page in the set

               s.insert(pages[i]);

               // push the current page into

               // the queue

               indexes.push(pages[i]);

               // Increment page faults

               page_faults++;

           }

       }

   }

   return page_faults;

}

// Driver code

int main()

{

   int pages[] = {7, 0, 1, 2, 0, 3, 0, 4,

               2, 3, 0, 3, 2};

   int n = sizeof(pages)/sizeof(pages[0]);

   int capacity = 4;

   cout << pageFaults(pages, n, capacity);

   return 0;

}

LRU

//C++ implementation of above algorithm

#include<bits/stdc++.h>

using namespace std;

// Function to find page faults using indexes

int pageFaults(int pages[], int n, int capacity)

{

   // To represent set of current pages. We use

   // an unordered_set so that we quickly check

   // if a page is present in set or not

   unordered_set<int> s;

   // To store least recently used indexes

   // of pages.

   unordered_map<int, int> indexes;

   // Start from initial page

   int page_faults = 0;

   for (int i=0; i<n; i++)

   {

       // Check if the set can hold more pages

       if (s.size() < capacity)

       {

           // Insert it into set if not present

           // already which represents page fault

           if (s.find(pages[i])==s.end())

           {

               s.insert(pages[i]);

               // increment page fault

               page_faults++;

           }

           // Store the recently used index of

           // each page

           indexes[pages[i]] = i;

       }

       // If the set is full then need to perform lru

       // i.e. remove the least recently used page

       // and insert the current page

       else

       {

           // Check if current page is not already

           // present in the set

           if (s.find(pages[i]) == s.end())

           {

               // Find the least recently used pages

               // that is present in the set

               int lru = INT_MAX, val;

               for (auto it=s.begin(); it!=s.end(); it++)

               {

                   if (indexes[*it] < lru)

                   {

                       lru = indexes[*it];

                       val = *it;

                   }

               }

               // Remove the indexes page

               s.erase(val);

               // insert the current page

               s.insert(pages[i]);

               // Increment page faults

               page_faults++;

           }

           // Update the current page index

           indexes[pages[i]] = i;

       }

   }

   return page_faults;

}

// Driver code

int main()

{

   int pages[] = {7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2};

   int n = sizeof(pages)/sizeof(pages[0]);

   int capacity = 4;

   cout << pageFaults(pages, n, capacity);

   return 0;

}

You can learn more about this at:

brainly.com/question/13013958#SPJ4

4 0
1 year ago
Why should you try to contact the technical support staff of a web hosting provider before you become one of its customers?
Marianna [84]

Answer: Contacting technical support can give you a general idea of the responsiveness of the web host provider to issues and problems. If the technical support staff is slow getting back to you at this point, don't be surprised if you get the same type of service when you have a problem and need immediate help. While not fail-safe, a quick response to a simple question at least gives the appearance of a well-organized, professional, and responsive technical support staff.

7 0
3 years ago
Which character is used to begin a comment?
Aloiza [94]
# is used to begin a comment.
8 0
3 years ago
There are several different types of RAM, each with its own purpose. Name the three types of RAM and briefly describe their func
Neko [114]
Well we have SRAM(Static Random Access Memory) is faster, have a lower density but it is more expensive.
While DRAM(Dynamic Random access memory) is just the opposite.
Those are the only two, I know exist.
3 0
4 years ago
Read 2 more answers
Other questions:
  • "Which of the following will help protect against a brute force attack?
    11·1 answer
  • In what country have regulators demanded that facebook stop collecting biometric data on its users?
    10·1 answer
  • Why when i create a powerpoint on word it doesn't open properly in other programmes
    5·1 answer
  • Evaluating how current, credible, and unbiased a source is ensures:
    7·1 answer
  • Do you think robots will take millions of jobs when they're put in different positions such as doctors or taxi drivers?
    7·1 answer
  • 100BaseT network uses the TCP/IP protocol suite exclusively, and workstations on your network obtain addresses dynamically from
    6·1 answer
  • A stateful inspection firewall ________. select one:
    14·1 answer
  • Display the total number of parking tickets.
    5·1 answer
  • Power supply, keyboard, monitor, mouse,ROM,CPU are belongs to Output, Input or Storage device​
    7·1 answer
  • The border to the right of a column is called the ____.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!