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
A ___________ is a variable used to pass information to a method.
Sauron [17]

A <em>parameter </em>is a variable used to pass information to a method.

3 0
2 years ago
Read 2 more answers
Trish has bought a new computer that she plans to start working on after a week. Since Trish has not used computers in the past,
kotegsom [21]
Hello, I am charlespierce576! I believe I might have the answer! Simple policies such as turning of off devices not in use. Also unplugging devices during a storm.
4 0
3 years ago
Management information system by different outhors<br>​
morpeh [17]

Answer:

Explanation:

.....

...,....

8 0
2 years ago
What does a transistor do?
mixas84 [53]

It Transmits electrical currents. You can use it as an amplifier or switch of currents.

5 0
3 years ago
Read 2 more answers
What happens to formulas with relative cell references when they are copied using the fill handle?
Masteriza [31]
The correct answer is D
4 0
3 years ago
Other questions:
  • What is a common method for testing a spot weld?
    13·1 answer
  • Why should spain go to Africa ​
    15·1 answer
  • What is the name of the program file that you can enter in the Windows search or Run box to execute Event Viewer? What process i
    12·1 answer
  • A simulation model includes: a. a description of the components of the system. b. a simulation clock. c. a definition of the sta
    8·1 answer
  • To determine the average of a range of numbers, click the ____ in the formula bar, then click average.
    13·1 answer
  • Public class Square extends Shape{
    13·1 answer
  • A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departme
    7·1 answer
  • A merchant bank and a merchant have been involved in a Web-based electronic transaction. Which of the following mediates between
    9·1 answer
  • How does the issue of cybersecurity relate to the internet of things?.
    5·1 answer
  • Write algorithm and flowchart for the following<br>a.find the sum and average of any four numbers ​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!