Write a function named list_sum that takes a list of values as input and returns the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function named list_sum that takes a list of values as input and returns the sum of all the values. For example, if the input is [3,5.0, 9] the function must return 17.0. Return 0.0 if the list is empty. You are not allowed to use the built-in function sum. You can assume that the input list contains only either float or int objects. print ("Test case 1: [4.25, 5.0, 10.75]") ans list sum ([4.25, 5.0, 10.75]) print (ans) print ("Test case 2: [5.0]") ans list_sum ([5.0]) print (ans) print ("Test case 3: []") ans list sum ([]) print (ans) The output should be: Test case 1: [4.25,5.0, 10.75] 20.0 Test case 2: [5.0] 5.0 Test case 3: [] 0.0 Ac 48 Gol Write a function named list_sum that takes a list of values as input and returns the sum of all the values. For example, if the input is [3,5.0, 9] the function must return 17.0. Return 0.0 if the list is empty. You are not allowed to use the built-in function sum. You can assume that the input list contains only either float or int objects. print ("Test case 1: [4.25, 5.0, 10.75]") ans list sum ([4.25, 5.0, 10.75]) print (ans) print ("Test case 2: [5.0]") ans list_sum ([5.0]) print (ans) print ("Test case 3: []") ans list sum ([]) print (ans) The output should be: Test case 1: [4.25,5.0, 10.75] 20.0 Test case 2: [5.0] 5.0 Test case 3: [] 0.0 Ac 48 Gol
Expert Answer:
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
Margaret is a baker who owns a small bakery called Pie in the Sky that sells cherry pies. She has been debating adding new pies into her offerings, including blackberry and apple. Margaret is...
-
(a) Use the following text to derive distributions for rat and chased. Use a five-word window, including open- and closed- class words, ignore case, punctuation and sentence boundaries and weight...
-
Use Figure 17.2 to explain why cost minimization through a tangency between an isoquant and a budget line does not apply in cases where D and M are either perfect complements or perfect substitutes....
-
Why do most firms not develop major strategies for matches between threats and strengths?
-
What is diversity? How has its meaning changed?
-
Consider the following cash flow profile, and assume MARR is 10 percent/year. a. What does Descartes' rule of signs tell us about the IRR(s) of this project? b. What does Norstrom's criterion tell us...
-
The stockholders equity accounts of G.K. Chesterton Company have the following balances on December 31, 2008. Common stock, $10 par, 300,000 shares issued and outstanding ... $3,000,000 Paid-in...
-
Display Oracle database employee last_name and salary for employee_ids between 100and 102. Include a third column that divides each salary by 1.55 and rounds the result two decimal places.
-
R.C. Willey's economists report that the quantity demanded for their microfiber sofas is given by the equation below. Px is their own price, C and D are other expensive good sold in the store with...
-
A.) What are the charges on plates 3 and 6? B.) If the voltage across the first capacitor (the one with capacitance C) is V', then what are the voltages across the second and third capacitors? C.)...
-
Before DeAndre can incorporate his advertising business in Atlanta, Georgia, he must have a. an agreement; Secretary of Commerce of the United States O b. a corporate charter; Atlanta city mayor O c....
-
Which field in the Orders table has a role of FOREIGN KEY in relation to Customers table? a ) ) CustomerID b ) ) OrderID c ) ) OrderDate d ) ) CustomerName
-
Of the following, who would be considered a stakeholder on a project? (Choose all that apply.) A B C D E F LL. G H M M Senior management of your organization End users of your product The project...
-
Q2- Write SQL commands for the following: 1. 2. List all details from the cars table for cars made before the year 2020.(3 points) Time left 0:49:01 Update table cars, Change type for car 90092 to...
-
Tamarisk Company purchased a truck for $74,700. The company expected the truck to last four years or 100,000 miles, with an estimated residual value of $6,700 at the end of that time. During the...
-
It is claimed that a stable and causal ideal selective filter can be obtained. Do you agree and disagree? If you agree provide an example of such a fiter. If you disagree. provide a proof of your...
-
Cable Corporation is 60% owned by Anna and 40% owned by Jim, who are unrelated. It has noncash assets, which it sells to an unrelated purchaser for $100,000 in cash and $900,000 in installment...
-
A language L is complete for a language class C with respect to polynomial-time reductions if L C and L P L for all L C. Show that ; and {0, 1} * are the only languages in P that are not complete...
-
For how many processors do the two versions of the chess programs run equally fast, assuming that T P = T 1/ P + T ?
-
Solve the following linear program using SIMPLEX: maximize 5x 3x2 subject to X1 X2 < 1 X2 < 2 > 0. 2x1 + X1, X2 |
-
In the absence of limits on the behavior of large intermediaries, how might the perception of institutions being too-big-to-fail lead to increased concentration in the banking industry?
-
One goal of the regulatory reforms that followed the 2007-2009 financial crisis was to address the too-big-to-fail problem associated with large institutions. How did the reforms try to address this...
-
Analyze how a government regulates and supervises the financial system to contain risk.
Study smarter with the SolutionInn App