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 of the following is not a method for opening Word software?
neonofarm [45]

Answer:

right clicking on the desktop and clicking "view"

8 0
2 years ago
Read 2 more answers
Where should you look for most objective and unbaised information
jekas [21]
Google, would be the best because of all of the different site, hope this helps!
: )
8 0
2 years ago
Brook is designing a database that customers can use to find their ideal vacation spot. If they only want to see beach vacations
Aleksandr [31]

Answer:

filter the data

Explanation:

its like when you filter a search on y o u t u b e and say u search among us u can filter and say live vids or channel's

7 0
2 years ago
Read 2 more answers
Write a loop that reads strings from standard input where the string is either "land", "air", or "water". The loop terminates wh
____ [38]

Answer:

count_land = count_air = count_water = 0

while True:

   s = input("Enter a string: ")

   if s == "xxxxx":

       break

   else:

       if s == "land":

           count_land += 1

       elif s == "air":

           count_air += 1

       elif s == "water":

           count_water += 1

print("land: " + str(count_land))

print("air: " + str(count_air))

print("water: " + str(count_water))

Explanation:

*The code is in Python

Initialize the variables

Create a while loop that iterates until a specific condition is met. Inside the loop, ask the user to enter the string. If it is "xxxxx", stop the loop. Otherwise, check if it is "land", "air", or "water". If it is one of the given strings, increment its counter by 1

When the loop is done, print the number of strings entered in the required format

4 0
3 years ago
what determines the best types of sketch or drawing to complete when you want to communicate your idea about a solution to a tec
Mekhanik [1.2K]
It depends on the problem. If you are solving a conplex one or simple
8 0
3 years ago
Other questions:
  • Write a program that assigns two integer values from standard input to the variables int1 and int2, then prints "true" if they a
    10·1 answer
  • You can use predesigned, formatted files called _____ to create new worksheets quickly.
    13·1 answer
  • Ted wants to follow the StartSafe philosophy when working around electricity. Which of the following steps would be consistent w
    15·2 answers
  • You have added a table to your web page consisting of two columns and five rows, including the header row. in the first header c
    13·1 answer
  • How to Create a while loop
    6·2 answers
  • Which of the following statements is true about a file stream?
    5·1 answer
  • Which expression is equivalent to 3x + 3x + 3x?<br><br> From Performance Matters
    11·2 answers
  • Global address list characteristics
    11·1 answer
  • ____ storage is not recommended for long-term archiving because the storage media can degrade over time
    15·1 answer
  • What option in the zone aging/scavenging properties dialog box will prevent dns record time stamps from being updated too often?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!