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
DENIUS [597]
3 years ago
8

Write a function that will sum all of the numbers in a list, ignoring the non-numbers. The function should takes one parameter:

a list of values (value_list) of various types. The recommended approach for this:
a. create a variable to hold the current sum and initialize it to zero.
b. use a for loop to process each element of the list.
c. test each element to see if it is an integer or a float, and, if so, add its value to the current sum.
d. return the sum at the end.
Computers and Technology
1 answer:
olasank [31]3 years ago
3 0

In python 3.8:

def func(value_list):

   lst = [x for x in value_list if type(x) == int or type(x) == float]

   return sum(lst)

print(func(["h", "w", 32, 342.23, 'j']))

This is one solution using list comprehensions. I prefer this route because the code is concise.

def func(value_list):

   total = 0

   for x in value_list:

       if type(x) == int or type(x) == float:

           total += x

   return total

print(func(["h", "w", 32, 342.23, 'j']))

This is the way as described in your problem.

You might be interested in
Select the first ICMP Echo Request message sent by your computer, and expand the Internet Protocol part of the packet in the pac
Luba_88 [7]

Answer:

You have to do that on your computer not someone elses....

Explanation: you have to do it

6 0
3 years ago
What do Business Analysis workers do? Check all that apply.
nlexa [21]

Answer: Recommend solutions to problems & Analyze information and problems.

A business analyst is a person that takes a look at a company's current system and tries to understand how the company works. These analyst seek to find out how the company will be in the future. Their main job is actually to oversee the different projects done by the company and analyze the different projects to determine if it would benefit the company or not.

Since business analysts thrive to understand their company's system, they are often the people who find information and problems that the company may have in the present or in the near future. These workers also recommend solution to problems that the company may have. The analysts are also often working with the IT departments of companies to help with the moving forward of the company's current system.

7 0
3 years ago
Read 2 more answers
Program to count how many even and odd number are in the range from M to N using C++ programming language
NemiM [27]

Answer:

#include<stdio.h>

#include <iostream>

using namespace std;

 

int main(){

   int number, min, max;

   cout << "Enter the minimum range: ";

   cin >> min;

  cout << "Enter the maximum range: ";

   cin >> max;

   cout << "Odd numbers in given range are: ";

   for(number = min; number <= max; number++)

        if(number % 2 !=0)

            cout << number<< " ";

   cout<< "Even numbers in given range are: ";

   for(number = min; number <= max; number++)

        if(number % 2 ==0)

            cout << number << " ";

 

   return 0;

}

Explanation:

First of all, we take declare two variables. one as the lowest number of the range and the other as the upper limit of the range (in this case: <em>min</em> and <em>max</em>). We declare another variable (<em>number</em>) and store in it the lowest number of the range (<em>min</em>). To check whether the number currently stored as the value of the variable (<em>number</em>) is even, we take in account the remainder of that number divided by 2. If the remainder does not equals 0, we print that number as odd. We again check the remainder by dividing the number by 2. If the remainder does equals 0, we print that number as even.

8 0
2 years ago
Samas vigrah of shvet putra​
kompoz [17]

Answer:

shvet putra kaa Sam's vigrah hai.

5 0
3 years ago
29. Write a program that asks to input any ten numbers and displays sum of them​
pogonyaev

Answer:

Here is the code for a classic C++ program that does it:

--------------------------------------------------------------------------------

#include <iostream>

using namespace std;

int main()

{

   int sum = 0;

   int n;

   cout << "Input 10 numbers: " << endl;

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

   {

       cin >> n;

       sum += n;

   }

   cout << "Sum of the numbers: " << sum << endl;

}

--------------------------------------------------------------------------------

Explanation:

I'm assuming you know what "include", "using namespace std" and "int main()" do, so I will skip over those.

First, we declare a variable "sum" and initialize it with 0 so we can add numbers to it later.

Then, we declare a variable "n" that will be set as the input of the user.

The "for-loop" will iterate ( go ) from 0 to 9, and will set the value of "n" as the input that is given -> "cin >> n;". After that, we add the value of "n" to the sum variable.

After "i" reaches 9, it will exit the loop and proceed to printing the sum of the numbers.

Hope it helped!

5 0
3 years ago
Other questions:
  • What I'd the keyboard shortcut for applying bold font to a text selection ​
    15·1 answer
  • Why do computers need system software?
    15·1 answer
  • A media scholar is trying to find out whether internet or television political ads are more persuasive. what kind of effects is
    7·1 answer
  • HELP ME ASAP PLS BEING TIMED
    8·2 answers
  • The use of electronic media, information, and communication technologies to deliver instruction where students are not required
    8·1 answer
  • What is the importance of computer application to statistics​
    6·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    7·1 answer
  • HELP ME PLEASE !!!!!
    10·1 answer
  • Why might a company choose Linux for its operating system instead of Microsoft Windows or Mac OS? The company's employees can sy
    13·1 answer
  • What changes the size of a video when played?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!