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
Ipatiy [6.2K]
2 years ago
6

Given a list of numbers, find the correct function to find the sum of the squares of only the positive elements.

Computers and Technology
1 answer:
vovikov84 [41]2 years ago
5 0

Answer:

sqsum4

Explanation:

So to raise a number to a power in python, you can use the ** operation, which is usually confused with the ^, which is an operation, but it is not for raising numbers to a power. It is the xor bit operation, which if you don't know at the moment, it's fine, since it's not necessary for this. each of these lists uses a generation comprehension which is generally defined as: (x for x in object if condition) with the if condition being optional, but in this case it's necessary. If it's a bit confusing, you can define a generator using a function so it's a bit more spread out:

def generator(object):

   for x in object:

       if condition:

           yield x

Although in this instance were going to be performing some operation on x, which in this case is squaring it. So let's just look at the two functions that use the **, since they should be the only options that will be correct.

sqsum1(nums):

   This function does square x, except it uses incorrect syntax. The condition should come after the for loop. Python likely wont tell you this, because it may think you're trying to do something else. You can do one line if statements like this: a if condition else b, which will return a if the condition is true, and b if it isn't. So it may think that you're trying to do this one line if statement, and say that you're missing an else. The function could even implement in this way: <em>x**2 if x > 0 else 0 for x in nums</em>. This way if the x is negative it counts as 0, or in other words isn't counted towards the sum. But without this fix, the function will raise a syntax error

sqsum4(nums):

   This will square each number in x only if the current element "x" is greater than 0, or in other words positive. And then it returns the sum. So this function returns the expected output

You might be interested in
Mention two hardware groups​
mars1129 [50]

Answer:

input Devices, Processing Devices, Output Devices, Memory/Storage Devices

Explanation:

4 0
3 years ago
Mary is writing an article about the software development life cycle. She wants to place a flowchart besides the text. Which men
vichka [17]
The answer to this question is that Mary should choose insert image . Then, in the wrap text Mary should choose “top and bottom” to add it below the text she wrote. Using the option Top and bottom - text appears at the top and bottom of the image.
4 0
3 years ago
Read 2 more answers
Can i get any information on this website i'd like to know what its for ?
zloy xaker [14]

Explanation: torsearch.org is a safe search engine mainly used for dark wed purposes. It does not track your location nor give any personal information.

8 0
3 years ago
Of the following choices, what indicates the primary purpose of an intrusion detection system (IDS)?
MrRa [10]
That would be (A) because an IDS stands for Intrusion detection system which means that when there’s malicious activity or policy violations. Any malicious activity or violation is typically reported either to an administrator.
8 0
3 years ago
10^4+10-2=<br>10^4+10-2=
yaroslaw [1]
10008 is the answer to your question
4 0
3 years ago
Read 2 more answers
Other questions:
  • Sean is white hat hacker, who is demonstrating a network level session hijack attacks and as part of it, he has injected malicio
    6·1 answer
  • What is an example of constructive criticism for an employee who is shy during meetings?
    15·2 answers
  • The operating system of a computer is an example of ________ software. science-forum
    7·1 answer
  • Data warehousing and data mining mean the same thing when applied to CRM
    7·2 answers
  • There are 22 gloves in a drawer: 5 pairs of red gloves, 4 pairs of yellow, and 2 pairs of green. You select the gloves in the da
    12·1 answer
  • Integer indexing array: Weekend box office The row array movieBoxOffice stores the amount of money a movie makes (in millions of
    11·1 answer
  • Is there any difference beetween the old version of spyro released on the origional and the newer ones??? or is it only change i
    8·1 answer
  • Sendddd meeeee memessss plsssssss
    8·2 answers
  • 24 POINTS!!! <br> Why are Sequences, Selection, and Iteration building blocks of algorithms?
    5·1 answer
  • MOA115 Medical Records and Insurance
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!