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
Name the technique used to separate the mixture of colours in black ink ​
Nitella [24]

Answer:

chromatography

hope it helps

6 0
2 years ago
Read 2 more answers
Help ME! Will Mark BRAINLIEST! Its Engineering!
Anettt [7]
What is it about ? And what you need help on
5 0
3 years ago
A heart murmur is caused by incorrect operation of ________?​
Levart [38]

Answer:

the valves

Explanation:

science explains your questions answer. also did you know that the queen was an engineer in WWII? you probably did but you need 20 characters to submit an answere trust me it is the valves.

6 0
3 years ago
WILL GIVE BRAINIEST! Your users are young children learning their arithmetic facts. The program will give them a choice of pract
Ierofanga [76]

In python:

numA = [4, 1, 6, 10, 2, 3, 7, 9, 11, 12, 5, 8]

numB = [2, 12, 10, 11, 1, 3, 7, 9, 4, 8, 5, 6]

while True:

   i = 0

   userChoice = input("Adding or Multiplying? (a/m) ")

   if userChoice == "a":

       while i < len(numA):

           answer = int(input("What is {} + {} ".format(numA[i],numB[i])))

           if answer == numA[i] + numB[i]:

               print("Correct!")

           else:

               print("That's incorrect. The right answer is {}".format(numA[i] + numB[i]))

           i += 1

   elif userChoice == "m":

       while i < len(numA):

           answer = int(input("What is {} * {} ".format(numA[i], numB[i])))

           if answer == numA[i] * numB[i]:

               print("Correct!")

           else:

               print("that's incorrect. The right answer is {}".format(numA[i] * numB[i]))

           i += 1

4 0
3 years ago
You have implemented a network where each device provides shared files with all other devices, what kind of network is it?
Reil [10]

It is a Peer-to-peer type of network when you have implemented a network where each device provides shared files with all other devices.

So the answer is Peer-to-peer.

8 0
3 years ago
Other questions:
  • What do you think about net neutrality??
    6·2 answers
  • The __________ certification program has added a number of concentrations that can demonstrate advanced knowledge beyond the bas
    10·1 answer
  • Which style of leadership would be most helpful to Charles in the following situation? Charles has just started an internship at
    15·1 answer
  • Consider the following code: // Merge mailing list m2 into m1 void merge (MailingList m1, MailingList m2) { for (int i = 0; i &l
    12·1 answer
  • Does trend in computing important for organization management?​
    8·1 answer
  • If a folder exists on an NTFS partition, which permission is needed by a user who needs to set security permissions on the folde
    11·1 answer
  • Kayla wants to know whether she should set her network up as a WAN or a LAN. What are the three questions you would ask her, and
    11·1 answer
  • Why is dark supereffective against ghost?
    5·2 answers
  • Please explain what steps you will take to prevent hackers from getting access to your personal information.
    7·1 answer
  • How have productivity programs improved the professional lives of people? (check all that apply)
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!