1. Read the file print() vs retum available in the LAB1 Assignment on Canvas. 2. Download...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Read the file print() vs retum available in the LAB1 Assignment on Canvas. 2. Download the starter code file from the LAB1 Assignment on Canvas. Do not change the function names or given started code on your script 3. A doctest is provided as an example of code functionality. Getting the same result as the doctest does not guarantee full credit (See Appendix for a quick introduction to the doctest module). You are responsible for debugging and testing your code with enough data. 4. Each function must return the output (Do not use print in your final submission, otherwise your submissions will receive a-1 point deduction) 5. Do not include test code outside any function in the upload. Printing unwanted or ill-formatted data to output will cause the test cases to fail. Remove all your testing code before uploading your file (You can also remove the doctest). 6. Do not include the input() function in your submission. |GOAL| Using your text editor, write the function sumSquares(aList). The function takes a list as an input and returns (not prints) the sum of the squares of the all the numbers which absolute value is divisible by 3. If an element in the list is not a number, the function should ignore the value and continue. When the function receives an input that is not a list, code should return an error message to the user. Hints: review the type() or isinstance() methods 10 def sumSquares(al ist): 11 12 13 14 error" > suiSquares('5') "error >>> sumSquares (6.15) 15 16 17 "error" 18 >>> sumSquares([1,5,-3,5,9,8,4]) 19 90 >>> sumSquares (['3',5,-3,5,9.0,8,4, Hello']) 20 21 90.0 22 23 %23 YOU CODE STARTS HERE 24 if type(alist) is not list: File "C:\Users\guo_h\Desktop\cmpsc132\1ab1\sumSquare.py", 1ine 24 25 return 'error 26 27 sun 0.0 for el in aList: if type(el) in (int, float]: sum el el 28 29 30 I 31 32 return sum 33 34 35 36 37 38 File "C:\Users \guo_h\Desktop\cmpsc132\labl\sumSquare.py", line 24 if type(alist) is not 1ist: IndentationError: unindent does not match any outer indentation level [Finished in 0.3s] 1. Read the file print() vs retum available in the LAB1 Assignment on Canvas. 2. Download the starter code file from the LAB1 Assignment on Canvas. Do not change the function names or given started code on your script 3. A doctest is provided as an example of code functionality. Getting the same result as the doctest does not guarantee full credit (See Appendix for a quick introduction to the doctest module). You are responsible for debugging and testing your code with enough data. 4. Each function must return the output (Do not use print in your final submission, otherwise your submissions will receive a-1 point deduction) 5. Do not include test code outside any function in the upload. Printing unwanted or ill-formatted data to output will cause the test cases to fail. Remove all your testing code before uploading your file (You can also remove the doctest). 6. Do not include the input() function in your submission. |GOAL| Using your text editor, write the function sumSquares(aList). The function takes a list as an input and returns (not prints) the sum of the squares of the all the numbers which absolute value is divisible by 3. If an element in the list is not a number, the function should ignore the value and continue. When the function receives an input that is not a list, code should return an error message to the user. Hints: review the type() or isinstance() methods 10 def sumSquares(al ist): 11 12 13 14 error" > suiSquares('5') "error >>> sumSquares (6.15) 15 16 17 "error" 18 >>> sumSquares([1,5,-3,5,9,8,4]) 19 90 >>> sumSquares (['3',5,-3,5,9.0,8,4, Hello']) 20 21 90.0 22 23 %23 YOU CODE STARTS HERE 24 if type(alist) is not list: File "C:\Users\guo_h\Desktop\cmpsc132\1ab1\sumSquare.py", 1ine 24 25 return 'error 26 27 sun 0.0 for el in aList: if type(el) in (int, float]: sum el el 28 29 30 I 31 32 return sum 33 34 35 36 37 38 File "C:\Users \guo_h\Desktop\cmpsc132\labl\sumSquare.py", line 24 if type(alist) is not 1ist: IndentationError: unindent does not match any outer indentation level [Finished in 0.3s]
Expert Answer:
Related Book For
Data Structures and Algorithm Analysis in Java
ISBN: 978-0132576277
3rd edition
Authors: Mark A. Weiss
Posted Date:
Students also viewed these programming questions
-
Write a Scheme function that takes a list as a parameter and returns a list identical to the parameter list except with the second top-level element removed. If the given list does not have two...
-
Write a Scheme function that takes a list as a parameter and returns a list identical to the parameter except the last element has been deleted.
-
If a number is divisible by 3 and 5, then the number is divisible by 15. Determine whether the statement is true or false. Modify each false statement to make it a true statement.
-
Necked Amber purchased a bond for $1,038.90 exactly two years ago. At that time, the bond had a maturity of five years and a coupon rate of 10% (paid semi-annually). Assuming the rates below are the...
-
For the following reactions, label each species as an acid or a base. Indicate the species that are conjugates of one another. a. b. c. d. Al(H2O)63 + + H2O Al(H2O)50H'+ + H30+ SO2NHHSONH
-
Assume Kaledan paid $18 million to purchase Southwest.com. Assume further that Southwest had the following summarized data at the time of the Kaledan acquisition (amounts in millions): Southwests...
-
1. Identify 3 students to play the roles of the employees. Ask these 3 individuals to read their roles below. 2. Identify 1 student to play the role of the president of the social enterprise (Taylor...
-
Oasis Health Care Inc. is owned and operated by Dr. George Hancock, the sole stockholder. During January 2013, Oasis Health Care entered into the following transactions: Jan. 1 Received $15,000 from...
-
(d) Suppose that instead of restricting imports or giving explicit advantages to Canadian-made products, the Bank of Canada enters the foreign exchange market and buys up large quantities of foreign...
-
Please look at the following graph and answer questions. If a node has more than one neighbor, visit the neighbors in alphabetical order. For example, when you iterate over the neighbors {A, F, D, Z}...
-
Automatic calculation and posting controls Rock Castle Construction *Open the Enter Bills window and select the Items tab. Enter the following for the vendor Patton Hardware Supplies, but do not...
-
What is naturalism? Is naturalism associated exclusively with an interpretive approach to research? Explain why or why not.
-
What criteria do you most often use when faced with an ethical dilemma? Which of the theories described in this chapter is the closest to your personal theory? Do you think any of the new ideas you...
-
Explain why GDP is not a good measure of social welfare.
-
Why do you think that natural opinion leaders were effective in delivering prevention messages in gay bars? Describe another situation where you think natural opinion leaders might be effective.
-
Do you believe that many Swiss dairy farmers really care about their animals as suggested in the text? Do you believe that many McDonald's executives really want to provide for an environmentally...
-
(1) Show the effect of the increase of M by the government using graphs. (Be careful about intersection points in the graphs.) (2) Using total differentiation, calculate the first (only LM), second...
-
What types of inventory issues Starbucks might reflect upon at the end of each year? The mission of Starbucks is to inspire and nurture the human spiritone person, one cup, and one neighborhood at a...
-
By changing the potential function, it is possible to prove different bounds for splaying. Let the weight function W(i) be some function assigned to each node in the tree, and let S(i) be the sum of...
-
a. Prove that 7 comparisons are required to sort 5 elements using any comparison based algorithm. b. Give an algorithm to sort 5 elements with 7 comparisons.
-
Implement the contains routine for MyLinkedList.
-
Let \(p(t, x)=(2 \pi t)^{-d / 2} \exp \left(-|x|^{2} /(2 t)ight), x \in \mathbb{R}^{d}, t>0\), be the transition density of a \(d\)-dimensional Brownian motion. a) Show that \(p(t, x)\) is a solution...
-
Let \(\left(B_{t}ight)_{t \geqslant 0}\) be a \(\mathrm{BM}^{d}\). Find all \(c \in \mathbb{R}\) such that \(\mathbb{E} e^{c\left|B_{t}ight|}\) and \(\mathbb{E} e^{c\left|B_{t}ight|^{2}}\) are finite.
-
Let \(\left(X_{t}, \mathscr{F}_{t}ight)_{t \geqslant 0}\) be a martingale and denote by \(\mathscr{F}_{t}^{*}\) be the completion of \(\mathscr{F}_{t}\) (completion means to add all subsets of...
Study smarter with the SolutionInn App