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
How was kapilvastu named​
mixas84 [53]

Answer:  Kapilvastu was named after Vedic sage Kapilamuni

4 0
3 years ago
The intersection of a row and a column is commonly called what?
Ierofanga [76]
I dont know the answer sorry i just need the points
6 0
3 years ago
Sample answers of What assets were targeted Stuxnet and the team behind the worm?
Damm [24]
The assets were programmable logic controllers (PLCs).  Which controlled systems like prison doors and centrifuges for separating nuclear material. 

The "who" is still debated.  Credit (if you use that word) is given to the Equation Group.  But that is still hotly debated as there seems to be a political agenda with the attack and many still believe this was nation-state sponsored.  I can be easy to leave digital fingerprints behind to make it seem like a known hacking team.
8 0
4 years ago
What is computer hardware?list any 4 computer hardware​
Scilla [17]

Computer hardware includes the physical parts of a computer, such as the case, central processing unit (CPU), monitor, mouse, keyboard, computer data storage, graphics card, sound card, speakers and motherboard. By contrast, software is the set of

8 0
3 years ago
Read 2 more answers
Many mobile computers and mobile devices use LCD monitors. What does LCD stand for?
erica [24]
Liquid crystal display
4 0
3 years ago
Other questions:
  • Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, a
    13·2 answers
  • Create a class CitiesAndCountries with at least three methods: class CitiesAndCountries: def add_country(self, country_name): ""
    7·1 answer
  • Caroline has been asked to find a standard to guide her company’s choices in implementing information security management system
    13·1 answer
  • Write a statement that declares a PrintWriter reference variable named output and initializes it to a reference to a newly creat
    5·1 answer
  • "Most of us know that when we come into a college classroom, we will see desks and chairs, a computer station and a projector. A
    6·1 answer
  • We wish to design a decoder, with three inputs, x, y, z, and eight active high outputs, labeled 0, 1, 2, 3, 4, 5, 6, 7. There is
    5·1 answer
  • Every modern nation has a Central Bank. Which of the following is the Central Bank for these United States?
    14·2 answers
  • Which of the following things can
    6·2 answers
  • Create a high-level plan to perform a gap analysis for Fullsoft Inc
    7·1 answer
  • True or false you can create a. network with 2 computers?<br>​
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!