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...
-
It has been suggested that plant and equipment could be replaced more quickly if depreciation rates for income tax and accounting purposes were substantially increased. As a result, business...
-
Let X = {0, 1, 2} and A = X X. Define the relation R on A as in Exercise 20. Answer the same questions posed in Exercise 20 for this relation R and set A. Exercise 20 For X = {0, 1}, let A = X X....
-
Trade secret theft can cause significant harm to a business. At the same time, businesses sometimes intentionally suppress information that might harm sales if publicly known. Suppose an employee of...
-
Shields Manufacturing produces containers for nurseries and landscaping businesses. The company competes based on its low-cost, high-quality products. As the company's expenses have risen, management...
-
1. 2. 3. (c) 11 Let f : R R be a continuous function such that f(3x)-f(x) =. If f(8) = 7, then f(14) is equal to: (a) 4 (b) 10 (d) 16 Let O be the origin and A be the point z = 1 + 2i. If B is the...
-
Consider the following linear programming problem Max 8X + 7Y s.t. 15X + 5Y < 75 10X + 6Y < 60 X + Y < 8 X, Y 0 a. Use a graph to show each constraint and the feasible region. b. Identify the...
-
Crane hoist is required to raise 300 kg weight at a speed of 0.40 m/s. The hook is mounted on a block which carries a single pulley sheave. One end of the hoisting cable is anchored on the crane...
-
If you are a corporate communications manager looking to leverage your skills for a position in internal communications, what would your career objective read like?
-
Search LinkedIn for three people in a profession that you might like to pursue and compare how they use the systems features to present themselves. Which person used LinkedIn most effectively? How...
-
Based on the preferences you identified in the self-assessment in the Prologue (see page 33) and the academic, professional, and personal qualities you have to offer, perform an online search for a...
-
Why is paying attention to an interviewers verbal and nonverbal cues as important as responding to questions?
-
Discuss why it could be useful to look for stepping-stone opportunities alongside specific job positions. Explain your answer.
-
Maslows Hierarchy of Needs and Alderfers ERG Theory aresimilar because both of them: 1) Suggest that individuals are motivated by a specific set ofneeds. 2) Suggest that punishment is more effective...
-
Suppose that a company has 10.000 outstanding shares in the beginning of the year. On April 1st, the company increases its shares by 6.000. On July 1st, the company increases its shares again, but...
-
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...
-
The file ApplianceShipments.csv contains the series of quarterly shipments (in million dollars) of US household appliances between 1985 and 1989 (data courtesy of Ken Black). a. Create a...
-
Canadian Manufacturing Workers Workhours. The time plot in Figure 17.9 describes the average annual number of weekly hours spent by Canadian manufacturing workers (data are available in...
-
Shampoo Sales. The file ShampooSales.csv contains data on the monthly sales of a certain shampoo over a three-year period. [Source: Hyndman and Yang (2018). a. Create a well-formatted time plot of...
Study smarter with the SolutionInn App