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
I have the assembly for the max. can someone change the variables of it and make it min. I mean, the assembly for finding the mi
tatyana61 [14]
Bruh i honeselty dont know
4 0
3 years ago
What is communication barriers?​
SSSSS [86.1K]

Answer:

A communication barrier is anything that prevents us from receiving and understanding the messages others use to convey their information, ideas and thoughts.They can interfere with or block the message you are trying to send.

7 0
3 years ago
Read 2 more answers
To accomplish a certain task when you would rsther be doing something else is an example of
fenix001 [56]

Answer:

Self Discipline

Explanation:

his is because you train your brain to do the right thing.

I hope I helped. Thank you for your time.

6 0
3 years ago
It would be at least two decades before some of the technologies he demonstrated saw widespread use, but all of them are used by
Phoenix [80]

Answer:

all of the above

Explanation:

7 0
3 years ago
What does DOS stand for?
anygoal [31]

Answer:

Disk Operating System

Explanation:

"DOS is a platform-independent acronym for Disk Operating System which later became a common shorthand for disk-based operating systems on IBM PC compatibles."

5 0
3 years ago
Other questions:
  • When u look at a green object through red glass the object will appear
    11·2 answers
  • What are voter purges
    11·1 answer
  • Please help me with this question. I don’t get it
    11·2 answers
  • Charts are more effective in attaining attentionthen others methods of presenting data. Do you agree?
    10·1 answer
  • Why is the cost of a software project not directly related to the cost of development?
    13·1 answer
  • What is the first step in creating a maintenance ?
    7·1 answer
  • What should be a technicians first step in an A/C system
    7·1 answer
  • Tạo thủ tục có tên _Pro04 để trả về số lượng tổng thời gian tham gia dự án Y của nhân viên có mã số X, với X là tham số đầu vào,
    5·1 answer
  • A numeric test score is to be converted to a letter grade of A, B, or C according to the following rules: A score greater than 9
    15·1 answer
  • A. Modify the FitnessTracker class that includes data fields for a fitness activity, the number of minutes spent participating,
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!