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
Given a string on one line and an integer index on a second line, output the character of the string at that index.
morpeh [17]

The code is in Java.

It uses a built-in function named chartAt() to get the character at the entered index.

Recall that built-in functions are functions that are already defined in the language. We can use them by calling the function and passing the required argument. The chartAt() function takes an index and returns the character at that index.

Comments are used to explain each line of the code.

//Main.java

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

    //Scanner object to get input from the user

    Scanner input = new Scanner(System.in);

   

    //Declaring the variables

    String s;

    int index;

    char c;

   

    //Getting the inputs

    s = input.nextLine();

    index = input.nextInt();

   

    //Getting the character at the index using the charAt() function

    c = s.charAt(index);

   

    //Printing the character

 System.out.println(c);

}

}

You may check the following link to see another similar question:

brainly.com/question/15688375

5 0
3 years ago
What would you need to have on your foley stage
LUCKY_DIMON [66]
<span>You will need many props for your Specific tracks (whatever you see in the film!). It's impossible to say what you will need until you see the picture and as time goes by you will add to your collection (if you have space!) - garbage day in my neighborhood is 'golden day' as I collect some of best props from the stuff people throw out: old bicycles, doors, sinks, wood, metal, desks, etc.</span>
4 0
3 years ago
Select the correct answer.
storchak [24]

Answer:

B. Planning

Explanation:

I believe the developer establishes the project goals in the planning phase.

6 0
4 years ago
Consumers must learn how to separate the truth from __ techniques
dmitriy555 [2]

Consumers must learn how to separate the truth from deceptive techniques.

Explanation:

Deceptive advertisements are hazardous for both consumer and advertiser. It is a misrepresentation of the nature of products or services promoted falsely by advertisers.

Professionals exploit consumers by following means:

  • false or incomplete information,
  • fraudulent activities
  • deceptive practices.

It may involve -

  • financial theft,
  • health risks,
  • scams, etc.  

Having proper knowledge about such practices and taking legal actions against fraudsters can help claim for the damages incurred.

3 0
4 years ago
The numbers, text, or cell references used by the function to return a value are called ____.
Alenkasestr [34]
The numbers, text or cell references used by the function to return a value are called ARGUMENTS. In computers and technology, arguments is referred to as a value that is assigned to something that returns when it is stated in a code.
8 0
4 years ago
Other questions:
  • You are working the 8:00 AM shift at the help desk. An irate user who fails to identify himself calls in claiming that his works
    7·1 answer
  • Write an application program that creates and prints a random phone number of the form XXX-XXX-XXXX. Include the dashes in the o
    5·1 answer
  • Your friend wants to know about Microsoft Expression Web 4. Which of the following terms will you use to describe Microsoft Expr
    5·1 answer
  • If a user wants to change one small section of the formatting of a document and leave the rest the same, which process should be
    14·1 answer
  • Which of the following refers to the data analysis software and interactive software that allow managers to conduct analyses and
    6·1 answer
  • The file format that an application can always open a named collection of data on a storage medium such as a hard disk or usb fl
    13·1 answer
  • Which of these communication avenues is not regulated by the Federal Communications Commission (FCC)?
    12·1 answer
  • my I phone is in recovery mode and when I connect to my PC the I device is not connected to iTunes although i have the latest ve
    7·2 answers
  • A capacitor of capacitance 102/π µF is connected across a 220 V, 50 Hz A.C. mains. Calculate the capacitive reactance, RMS value
    8·1 answer
  • Why does a bus topology require a terminator? a) because otherwise it would be a ring network b) because otherwise the packets w
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!