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
Digiron [165]
3 years ago
15

Sublist(xs, total)'

Computers and Technology
1 answer:
motikmotik3 years ago
5 0

Answer:

# ths functionfind a sub matrix from the list

def findSubMatrix(xs, startR, startC, size):

   # an empty list named data is initialized

   data = []

   for i in range(startR, startR+size):

       row = []

       for j in range(startC, startC+size):

           row.append(xs[i][j])

       data.append(row)

   return data

# this function find the sum of each list in the matrix

def FindSum(matrix):

   # s represent the sum and is initialized to 0

   s = 0

   # loop through the matrix

   # sum each list and add to s

   for m in matrix:

       s += sum(m)

   # the value of s is returned

   return s

# this function return a sublist

def sublist(xs, total):

   # length of entire list is assigned to r

   r = len(xs)

   # length of first list is assigned to c

   c = len(xs[0])

 

   # for loop that loop from 2 to least value between r and c

   for size in range(2, min(r, c) + 1):

       # None is first assigned to result

       result = None

       for startR in range(0, r-size+1):

          for startC in range(0, c-size+1):

               d = findSubMatrix(xs, startR, startC, size)

               # findSum is use to compute the sum of d

               s = FindSum(d)

               # if s is greater than total

               # and if result is None or the sum of result is less than s

               # d is assigned to result

               if s > total:

                   if result is None or FindSum(result) < s:

                       result = d

       # if result is not None, it is returned

       if result is not None:

           return result

   return None

# the sublist function is called having two parameter

# a list of list of integer and a total

print(sublist([[0,1,2], [-4,5,6], [7,8,3]], 5))

print(sublist([[0,1,2], [-4,5,6], [7,8,3]], 23))

Explanation:

The program is written in Python and well commented. An image showing the output of the program when executed is attached.

You might be interested in
A red wavy line under a word means _____. a change has been made in the text a new word was inserted in the document there is a
zloy xaker [14]
Hi there!

The correct option is C. <span>there is a spelling mistake. The red wavy line indicates that a word was spelled incorrectly, sometimes though this function does not recognize the word it can mark it as incorrect even when it is not, in which case you can right-click the marked word and add it to your computer's internal word dictionary. Right-clicking an incorrectly spelled word will also give a short list of words that are similar to the one you are trying to spell, clicking on one of the given words will automatically change the marked word to the one you chose.

-Your friend, ASIAX</span>
7 0
4 years ago
Read 2 more answers
You are given an array of integers, each with an unknown number of digits. You are also told the total number of digits of all t
Vlad [161]

Answer:

Explanation:

Since all of the items in the array would be integers sorting them would not be a problem regardless of the difference in integers. O(n) time would be impossible unless the array is already sorted, otherwise, the best runtime we can hope for would be such a method like the one below with a runtime of O(n^2)

static void sortingMethod(int arr[], int n)  

   {  

       int x, y, temp;  

       boolean swapped;  

       for (x = 0; x < n - 1; x++)  

       {  

           swapped = false;  

           for (y = 0; y < n - x - 1; y++)  

           {  

               if (arr[y] > arr[y + 1])  

               {  

                   temp = arr[y];  

                   arr[y] = arr[y + 1];  

                   arr[y + 1] = temp;  

                   swapped = true;  

               }  

           }  

           if (swapped == false)  

               break;  

       }  

   }

8 0
3 years ago
In this lab, you complete a prewritten Python program for a carpenter who creates personalized house signs. The program is suppo
ivolga24 [154]

Using the computer language in python to write a function code that personalized house signs

<h3>Writting the code in python:</h3>

<em>#Assign varibles</em>

<em>charge = 0.00</em>

<em>numChars = 8</em>

<em>color = "gold"</em>

<em>woodType = "oak"</em>

<em />

<em>#Checking for number of characters</em>

<em>if numChars > 5:</em>

<em>charge = 35 + (numChars-5)*4</em>

<em>elif numChars > 0:</em>

<em>charge = 35</em>

<em />

<em>#Checking wood type</em>

<em>if woodType == "oak":</em>

<em>charge += 20</em>

<em />

<em>#Checking for color</em>

<em>if color == "gold":</em>

<em>charge += 15</em>

<em />

<em>#Print output</em>

<em>print("The charge for this sign is $"+str(charge)+".")</em>

See more about python at brainly.com/question/13437928

#SPJ1

5 0
2 years ago
Adam is evaluating the security of a web server before it goes live. He believes that an issue in the code allows an SQL injecti
givi [52]

The term vulnerability describes the issue that Adam discovered.

b. vulnerability

<u>Explanation:</u>

SQL injection attack is an attack in which an external party can execute SQL commands on the database that serves as a back-end for a particular website. The SQL commands can be used to modify the contents of the website, modify the records, delete the records, and retrieve confidential information as well.  

As Adam believes that the code has an issue that allows a SQL injection attack, the term that best describes the issue that he discovered is vulnerability. The website is vulnerable since the code does not have a proper procedure to tackle a situation of SQL injection attack.

7 0
4 years ago
This is gonna be very long but I have no idea what to do, I'm confused.
kaheart [24]

for such experiment, you do it with care and to acquire and determine to put experience in it

Explanation:

because without you been or using experience the experiment will not correct

8 0
3 years ago
Other questions:
  • Consider two sets S1 and S2 of size 3 and 2 each.
    13·1 answer
  • A(n) _____ is a type of server that stores computer software, which users can access from their workstations.
    6·1 answer
  • Where can you place CSS statements in an HTML file?
    7·1 answer
  • The level of competition is an important factor for many people when selecting a physical activity.
    7·2 answers
  • The interaction between information technology and organizations is influenced___________.A) solely by the decision making of mi
    12·1 answer
  • Which one is correct
    8·1 answer
  • A software development company wants to reorganize its office so that managers and the Computer Programmers they supervise can b
    13·2 answers
  • You are configuring two PCs for your network, PC-A is given an IP address of 192.168.1.18 and PC-B is given an IP address of 192
    15·1 answer
  • Which of the following does Secure Sockets Layer (SSL) use to authenticate a user or system before encrypting a session?
    14·1 answer
  • Which one causes concerns for institutions or businesses when they are collected stores and they aren’t secured properly?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!