For each of the following Python functions, write their code complexity in big O notation. i)...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
For each of the following Python functions, write their code complexity in big O notation. i) def print_half (numbers): """Print half of the numbers (added by 1). """ for i in range(0, len (numbers)//2 + 1): number = numbers [i] + 1 print (number) ii) def print_something (num): """Print recursively. if num <= 1: print (num) else: ### print (num, end=" ") print_something (num // 2) iii) def add_numbers (n): end_number = 2 ** n iv) def v) def count = 0 for i in range(0, end_number): count += i return count get_first_last (array): return array[0], array[len(array) - 1] print_times_table(n): for i in range (1, n+1): for j in range(1, 13): print (f"{i*j:3}", end="") print() b) Consider the following Python list of items: numbers = [ 9, 84, 12, 3, 25, 34, 31, 65, 53 ] i) Using list comprehensions, write code to obtain the following: [81, 7056, 144, 9, 625, 1156, 961, 4225, 2809] # squares of each numbers 3 # count of numbers that are even. [5] ii) Write the load_scores() function to read a file with the following scores.csv into a list of floats. Write another function get_average() to calculate the average score. When the codes below are run, the output should show the following: [10] scores load_scores ("scores.csv") average_score= get_average (scores) print (f"Average score is (average_score:.1f}") contents of scores.csv vick, 83.2 siti,78.1 zen, 57 lucas, umbras, 77.7 66 fred, 35.8 stan, 93.2 lily, 37.7 Output: Average score is 66.1 For each of the following Python functions, write their code complexity in big O notation. i) def print_half (numbers): """Print half of the numbers (added by 1). """ for i in range(0, len (numbers)//2 + 1): number = numbers [i] + 1 print (number) ii) def print_something (num): """Print recursively. if num <= 1: print (num) else: ### print (num, end=" ") print_something (num // 2) iii) def add_numbers (n): end_number = 2 ** n iv) def v) def count = 0 for i in range(0, end_number): count += i return count get_first_last (array): return array[0], array[len(array) - 1] print_times_table(n): for i in range (1, n+1): for j in range(1, 13): print (f"{i*j:3}", end="") print() b) Consider the following Python list of items: numbers = [ 9, 84, 12, 3, 25, 34, 31, 65, 53 ] i) Using list comprehensions, write code to obtain the following: [81, 7056, 144, 9, 625, 1156, 961, 4225, 2809] # squares of each numbers 3 # count of numbers that are even. [5] ii) Write the load_scores() function to read a file with the following scores.csv into a list of floats. Write another function get_average() to calculate the average score. When the codes below are run, the output should show the following: [10] scores load_scores ("scores.csv") average_score= get_average (scores) print (f"Average score is (average_score:.1f}") contents of scores.csv vick, 83.2 siti,78.1 zen, 57 lucas, umbras, 77.7 66 fred, 35.8 stan, 93.2 lily, 37.7 Output: Average score is 66.1
Expert Answer:
Answer rating: 100% (QA)
Explanation i printhalfnumbers code def printhalfnumbers for ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Martinez Company's relevant range of production is 7,500 units to 12,500 units. When it produces and sells 10,000 units, its average costs per unit are as follows: Average Cost Per Unit Fixed...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
Consider a property investment that you finance with 20% down payment. For the remaining, you borrow 2'300'000 at a 6% rate monthly amortized loan for 25 years. This property, with 2% of EBITDA as...
-
Grant Lawson has just been appointed as the new financial controller of Safety Chemicals Ltd, which has three separate divisions Industrial Chemicals, Paints, and Household Chemicals. During his...
-
A sample of Kr(g) escapes through a tiny hole in 87.3 s. The same amount of an unknown gas escapes in 42.9 s under identical conditions. What is the molar mass of the unknown gas?
-
On 31 March 2003, Son Ltd had issued share capital of 75,000 ordinary 1 shares and reserves of 40,000. Two years later, the reserves had risen to 60,000 but the share capital was unchanged. Pa Ltd...
-
Alternative joint-cost-allocation methods, further-process decision. The Wood Spirits Company produces two productsturpentine and methanol (wood alcohol)by a joint process. Joint costs amount to...
-
Prime, Inc., bottles and distributes mineral water from the company's natural springs in northem Oregon. Prime markets two products: 12-ounce disposable plastic bottles and 1-galon reusable plastic...
-
For each of the following employees, calculate the Social Security tax for the weekly pay period described: For simplicity, all calculations throughout this exercise, both intermediate and final,...
-
Describe a time when you had the opportunity to delegate a task to an employee or a task was delegated to you by another employee. What were some of the lessons (favorable or unfavorable) you gained...
-
How is the "place" element of the 4 P's of the marketing mix related to the concept of distribution? 2) What are three essential elements to create an effective distribution channel? Feel free to...
-
There were no budgeted and actual opening- or closing inventory of any type for June 2021. Mrs Felafela, Chief Financial Officer (CFO) solely approved the contract with Switch (Pty) Ltd that they...
-
How Safe is Safe? Sometimes what is legal is not ethical. Do you agree or disagree with that statement? Why or why not? Do you expect leaders to be ethical? What leader (past or present) do you see...
-
You have $2,500 to invest now and you estimate the average inflation rate to be 5% per year in the next 5 years. Ignoring income taxes, analyze the following situations and indicate which one is more...
-
Final (15)4.) For the given cash flow determine the present amount "P", the future sum "F" and the uniform series "A" for the given flow if the interest rate is 7.696% compounded continuously. Year I...
-
Match the following changes to account balances to how they would be included in the indirect method for determining operating cash flows. Would the change be added to Net Income? Or deducted from...
-
What are the two components of a company's income tax provision? What does each component represent about a company's income tax provision?
-
Karim Depak received a Form 1099-B showing the following stock transactions and basis during 2012: None of the stock is qualified small business stock. Calculate Karim's net capital gain or loss...
-
John Fuji (age 37) moved from California to Washington in December 2011. He lives at 468 Cameo Street, Yakima, WA 98901. John's Social Security number is 571-78-5974 and he is single. His earnings...
-
Jan has two jobs during 2012. One employer withheld and paid FICA taxes on $66,600 of Jan's salary, and the other employer withheld and paid FICA taxes on $44,400 in salary paid to Jan. Calculate the...
-
12. Frank B. McMahon wrote one of the first psychology textbooks to feature a light and easily readable style. He also included many colloquialisms and examples that appealed to a youthful student...
-
11. Harper & Row signed a contract with former President Gerald Ford to publish his memoirs. As part of the deal, the two agreed that Time magazine could print an excerpt from the memoirs shortly...
-
13. ROLE REVERSAL Draft a multiple-choice question that focuses on an issue of copyright law. 4. Result: Parody (especially about politics!) is a fair use of copyrighted material as long as use of...
Study smarter with the SolutionInn App