Describe the building blocks of computers and programs based on your understanding and answer this question....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Describe the building blocks of computers and programs based on your understanding and answer this question. You are given the following code segments: 1 def add1(a, b): (a) 2 3 4 a = a+b print('In add1: ', a, b) 5e def add2(a, b): 6 7 8 a.append(b) print('In add2: ', a, b) 9 def main(): 10 a = [1] 11 b = [2] 12 add1(a, b) 13 print('In main: ', a, b) 14 a = [1] 15 b = [2] 16 add2(a, b) 17 print('In main: ', a, b) 18 19 main() (i) What is the output of the code segment when it is executed? (4 marks) Explain in terms of assignment statements and mutability, the output you gave for part (i). (4 marks) (b) (c) (i) (ii) 1 a, b 1, 9 2 while True: 3 456 if abs(a * a- b) <0.00000000000001: = break a (a + b/a)/2 6 print(a) The values of variable a at line 5 in the iterations of the while loop are as follows: 5.0 3.4 3.023529411764706 3.00009155413138 3.000000001396984 3.0 Explain in ONE (1) sentence what the code segment does. (3 marks) Will the code segment be able to perform the purpose you specify in Q1(b)(i) if the statement on line 5 is changed to: a = (a + b)/2? Explain. 1 a = '123456' 2 for i in range(len(a)-1, -1, -1): (6 marks) 3 print(a[i::2]) (i) List out the values generated by the expression: range(len(a)-1, -1, -1). (2 marks) (ii) Explain in ONE (1) sentence what the code segment does. (4 marks) (iii) What is the output of the code segment when it is executed? (2 marks) Describe the building blocks of computers and programs based on your understanding and answer this question. You are given the following code segments: 1 def add1(a, b): (a) 2 3 4 a = a+b print('In add1: ', a, b) 5e def add2(a, b): 6 7 8 a.append(b) print('In add2: ', a, b) 9 def main(): 10 a = [1] 11 b = [2] 12 add1(a, b) 13 print('In main: ', a, b) 14 a = [1] 15 b = [2] 16 add2(a, b) 17 print('In main: ', a, b) 18 19 main() (i) What is the output of the code segment when it is executed? (4 marks) Explain in terms of assignment statements and mutability, the output you gave for part (i). (4 marks) (b) (c) (i) (ii) 1 a, b 1, 9 2 while True: 3 456 if abs(a * a- b) <0.00000000000001: = break a (a + b/a)/2 6 print(a) The values of variable a at line 5 in the iterations of the while loop are as follows: 5.0 3.4 3.023529411764706 3.00009155413138 3.000000001396984 3.0 Explain in ONE (1) sentence what the code segment does. (3 marks) Will the code segment be able to perform the purpose you specify in Q1(b)(i) if the statement on line 5 is changed to: a = (a + b)/2? Explain. 1 a = '123456' 2 for i in range(len(a)-1, -1, -1): (6 marks) 3 print(a[i::2]) (i) List out the values generated by the expression: range(len(a)-1, -1, -1). (2 marks) (ii) Explain in ONE (1) sentence what the code segment does. (4 marks) (iii) What is the output of the code segment when it is executed? (2 marks)
Expert Answer:
Related Book For
Systems analysis and design in a changing world
ISBN: 978-1423902287
5th edition
Authors: John W. Satzinger, Robert B. Jackson, Stephen D. Burd
Posted Date:
Students also viewed these finance questions
-
"internet radios" for streaming audio, and personal video recorders and players. Describe design and evaluation processes that could be used by a start-up company to improve the usability of such...
-
This assignment requires you to complete the 2022 tax reporting for a fictional woman named Anna Smith. Question 1 T1 - step 4 - line 66 This is Anna's taxable income Answer: Question 2 T1 - step...
-
Use the test of your choice to determine whether the following series converge. 1 + 1.3 1 3.5 + 1 5.7
-
Each business day, on average, a company writes checks totaling $23,400 to pay its suppliers. The usual clearing time for the checks is four days. Meanwhile, the company is receiving payments from...
-
Find the length of a circular arc with a radius 12 centimeters subtended by the central angle of 30.
-
A person donates a bag of clothes to Goodwill completely unaware that there is valuable sterling silver in the bag. The clothing and silver are subsequently sold, for a very economical price, to...
-
Johnson Cogs wants to set tip a line to serve 60 customers per hour. The work elements and their precedence relationships are shown in the following table. a. What is the theoretical minimum number...
-
15. You are provided with cost data for the Amber Amazing Restaurant for its signature dinner dish that it offers to its patrons. Use the following figure for this business to answer the questions...
-
Here are three countries: Cote dIvoire; Tanzania and Malawi. You are writing a report for the Secretary of State of British Government where a decision is needed as to which country the government...
-
Many physical phenomena are modeled by partial differential equations, or equations involving partial derivatives. The simplest example is the transport equation: u u + c t = 0 (1) which models a...
-
Suppose the one year forward rate for Brazilian Real (BRL) versus the USD is F360 (BRL/$) = 2.8 The current spot rate is S (BRL/$) = 2.2 Annual interest rate in Brazil = 10% Annual interest rate in...
-
You plan to deposit $1,000 today, $5,000 in one year and $1,000 in two years in an account earning 6.0% interest. What will the account balance be in 4 years? Round to the nearest cent.
-
Winston Inc. is trying to determine the effect of its inventory turnover ratio and days sales outstanding on its cash conversion cycle. Winston's 2017 sales (all on credit) were $117,000 and its cost...
-
Calculate the after-tax cost of the debt under each of the following conditions: a. rd of 5%, tax rate of 12% b. rd of 5%, tax rate of 32% c. rd of 5%, tax rate of 42%
-
Gruber (2000) found evidence that the elasticity of labor supply with respect to disability insurance benefits is considerably smaller than the estimates of the elasticity of unemployment durations...
-
Revol Industries manufactures plastic bottles for the food industry. On average, Revol pays $76 per ton for its plastics. Revol's waste-disposal company has increased its waste-disposal charge to $57...
-
Visit a restaurant or the college food service and talk to a server (or talk with a friend who is a food server). Ask about the external events, temporal events, and data entities or objects, as you...
-
What is a persistent class?
-
Sketch the layout of your room at home. Now write a description of the layout of your room. Are these both models of your room? Which is more accurate? More detailed? Easier to follow for someone...
-
The group \(\mathrm{D}_{3}\) in Schoenflies notation (32 in international notation, which is read "three-two"; see Table 5.1 ) consists of the proper (those not reflections or inversions) covering...
-
Derive the two-dimensional matrix representation Tic)=(2) Tin)=(3) Tex)=(37) (69) T(c2b)= 1 TO)-(71) 10-(11) TO=(9) = for the group D3, using the basis (e1, e2) defined in the following figure.
-
Prove that the matrix representation of \(\mathrm{D}_{3}\) worked out in Problem 5.6 is irreducible. Data from Problem 5.6 Derive the two-dimensional matrix representation Tic)=(2) Tin)=(3)...
Study smarter with the SolutionInn App