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
In the circuit seen here, the resistor has a resistance of 3 ohms. If no change in the battery size occurs, what will happen to
Rufina [12.5K]

It will increase by a factor of 2

6 0
3 years ago
Read 2 more answers
Which method(s) must a serializable class, implement?
Cloud [144]

Answer: None of the given option is correct

Explanation:

A serializable class is implemented, when an object is serializable interface. If you want to serialize one of your classes, then the class must implemented in the Serializable interface. To implement the serializable interface, convert a class into the series of bytes and when serializable object might reference your class. Serializable classes are useful when you wanted to persist cases of the class or send them over wire.

5 0
3 years ago
1. Think about the various ways in which you have seen hackers portrayed in popular media over the past few years. Are they hero
Eva8 [605]
They are definitely not heroic characters, so you can rule that out. Definitely dangerous criminals. If you need me to help further I can. Is that a question or an essay?
3 0
3 years ago
Adding videos to your website can be tricky because there may be problems making sure they will play in all
Volgvan
The sentence ends with the word 'devices'
4 0
3 years ago
Dsc test transmission may​
Drupady [299]
Wait what? Stream blue hour tho$
4 0
3 years ago
Other questions:
  • Which speaker port should you use when connecting a single speaker to a pc?
    6·1 answer
  • Can an iphone user see when an android user is typing
    10·2 answers
  • Software that was designed to serve the needs of a specific company or organization is called:
    11·1 answer
  • What color mode would you use when designing for web & devices?
    9·1 answer
  • Select the correct answer.
    15·2 answers
  • Imma say something random...
    13·2 answers
  • While all pages use HTML code, not all pages are written in
    15·2 answers
  • Complete the function favoriteFlower(). Note that the program will not run as is because the function is incomplete. The purpose
    15·1 answer
  • How do you properly turn off a computer?
    8·2 answers
  • EXERCISE
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!