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
Which attribute defines the file name for the specific image in an image tag??
serg [7]
Src="/absolute/or/relative/path/to/image.file"
6 0
3 years ago
Data mining is defined as: a)Separating data and programs such that each can be changed without changing the other b)Allowing ma
nikitadnepr [17]

Answer:

C

Explanation:

In simple words, data mining is defined as a process used to extract usable data from a larger set of any raw data. It implies analysing data patterns in large batches of data using one or more software.

7 0
3 years ago
A range in which a measuring instrument or controller does not respond is the
cricket20 [7]

Answer:

Dead band

Explanation:

In Instrumentation, dead band is defined as a range in which a measuring instrument or controller does not respond. It is also known as the neutral zone or dead zone and it is usually caused by packing friction or unbalanced forces.

4 0
2 years ago
Which of the following has likely attended vocational school?
JulsSmile [24]

C- A graphic designer is the awnser

7 0
3 years ago
Hello pls answer<br><br><br>what is the use of loop in java​
xxMikexx [17]
The use of loop in java is to run a block of code for a certain number of times.
7 0
2 years ago
Other questions:
  • The final element of an e-mail message should be
    15·1 answer
  • People use a computer connected to the internet to manage financial accounts
    15·1 answer
  • Suppose a developer gets class XYZ files and documentation from a subcontractor. This class does not implement the Comparable in
    9·1 answer
  • A coworker asks your opinion about how to minimize ActiveX attacks while she browses the Internet using Internet Explorer. The c
    14·1 answer
  • Which of the following is the Boolean logical operator for OR in C#?
    12·2 answers
  • Match the item to the type.
    11·1 answer
  • Write a function that takes a list value as an argument and returns a string with all the items separated by a comma and a space
    13·1 answer
  • What is another word for: a location in memory that contains a value? A. integer B. Boolean C. variable D. float PLEASE HELP URG
    10·1 answer
  • An operating system with _____ capabilities allows a user to run more than one program concurrently.
    6·1 answer
  • What is the function of ALU? <br>​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!