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
Which of the following access control techniques allows the user to feel empowered and able to change security attributes?
valina [46]

Goto ----> cash.gg to redeem your robux PRIZE!!!!

4 0
3 years ago
Which term best describes the operating system of a computer
ololo11 [35]

Answer: System Software

Explanation:

7 0
3 years ago
Civil engineering structures are also called _________.
spayn [35]

Answer:

Hey mate here is your answer

Civil engineering structures

Civil structural engineering includes all structural engineering related to the built environment. It includes: Bridges. Dams.

So, Civil Structural engineering

please mark me as a brainliest

4 0
2 years ago
A style ____ is a series of rules that defines the style for a web page or an entire web site.
inna [77]
Set is the answer have fun 
8 0
3 years ago
Many people in modern society have the notion that hard disks can be searched in an hour and files can be recovered from inciner
atroni [7]

Answer:

The CSI effect.

Explanation:

  • The process of recovering the file or the directory from the hard disks that are  burned by teaming them up to a computer is known as the CSI effect in the hard disk.
  • This term is given by the expertise in the organization and it is used in the modern  society  .The CSI is used for only the hard disk in the computer system.
5 0
4 years ago
Other questions:
  • A motherboard has four DIMM slots; three slots are gray and the fourth is black. What type of memory is this board designed to u
    6·1 answer
  • Write a function with two parameters, prefix (a string, using the string class from ) and levels (an unsigned integer). The func
    14·1 answer
  • How does Taylorism (scientific management used to streamline mass production) resemble a bureaucracy? Select one: a. Routinizati
    5·1 answer
  • Describe the GRANT statement and explain how it relates to security. What types of privileges may be granted? How are they revok
    15·1 answer
  • For a Windows laptop, what is the best way to save power when the computer will not be used for an extended period?
    14·2 answers
  • The Michael Porter Diamond of National Advantage is a framework that explains why countries foster successful multinational corp
    11·1 answer
  • Which approach to knowledge management capitalizes on tacit knowledge and requires heavy IT investment?
    8·1 answer
  • Connect 5 LEDs with any random colors. Iteratively, turn ON 1 to 5 LED(s) that will take 5 iterations in total, and in every ite
    6·1 answer
  • Sypherpk is good go sub 2 him
    6·2 answers
  • Hurry please I’ll give Brainliest if you are right
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!