4) Trace this program in the following table by filling in the initial values of variables...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
4) Trace this program in the following table by filling in the initial values of variables and also the values whenever they change. def fn(a,b): if a <b: r=1 elif a > bi r-2 else: L 2-3 return r L-12, 5, 17, 17, 61 i-1 typel = True type2 - True while i < len(L): x-L[i-1] res fn(x,L[i]) if res-1: typel-False elif res = 2: type2= False i=i+1 print (type1, type2) ID i typel type2 X LOG b) What is the output of this program? That is, what is printed? a b T res Write the Python code for the following function fn(a,b) where a and bare two integers and a is less than or equal to b. This function returns the sum of the numbers between a and b (not including a and b). For example, calling fin(1,5) would return 9 (which is the sum of 2+3+4) For another example, calling fn(2,3) would return 0 (since there are no numbers between 2 and 3) b) Write a Python program that inputs two integers x and y. The program will print the sum of the numbers that occur between x and y. You must use the function in part 2(a). Note, the user might not enter the numbers in order (e.g. x could be greater than y). For example, if the input is 1 5, then the output should be 9 If instead the input is 5 1, the output should also be 9. 4) Trace this program in the following table by filling in the initial values of variables and also the values whenever they change. def fn(a,b): if a <b: r=1 elif a > bi r-2 else: L 2-3 return r L-12, 5, 17, 17, 61 i-1 typel = True type2 - True while i < len(L): x-L[i-1] res fn(x,L[i]) if res-1: typel-False elif res = 2: type2= False i=i+1 print (type1, type2) ID i typel type2 X LOG b) What is the output of this program? That is, what is printed? a b T res Write the Python code for the following function fn(a,b) where a and bare two integers and a is less than or equal to b. This function returns the sum of the numbers between a and b (not including a and b). For example, calling fin(1,5) would return 9 (which is the sum of 2+3+4) For another example, calling fn(2,3) would return 0 (since there are no numbers between 2 and 3) b) Write a Python program that inputs two integers x and y. The program will print the sum of the numbers that occur between x and y. You must use the function in part 2(a). Note, the user might not enter the numbers in order (e.g. x could be greater than y). For example, if the input is 1 5, then the output should be 9 If instead the input is 5 1, the output should also be 9.
Expert Answer:
Answer rating: 100% (QA)
Solution Lets start by tracing the given program def fna b if a b elif a b r2 else 83 return r L 12 ... 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
-
What are genetic mutations, and how do they happen? When a genetic mutation happens how does it effect the body? How does DNA affect genetic mutations ?
-
The data listed in the following table relate to a study by Reiter and others (1981) concerning the effects of injecting triethyl-tin (TET) into rats once at age 5 days. The animals were injected...
-
The data in the following table and accompanying computer output are from a hypothetical study of human body temperature as affected by air temperature and a dietary supplement that is hoped to...
-
The MLC Corporation produces electronic microwave ovens and uses a perpetual inventory system. Its job costing records yield the following information. Job No. 1 m 2 3 4 *5 6 7 Date Finished Sold...
-
Ammonia and amines undergo conjugate addition to a, -unsaturated carbonyl compounds (Section 18.12). On the basis of this information, predict the principal organic product of each of the following...
-
Bill and Guilda each own 50 percent of the stock of Radiata Corporation, an S corporation. Guilda's basis in her stock is $25,000. On July 31, 2013, Bill sells his stock, with a basis of $40,000, to...
-
During a quality assurance check, the actual weights (in kilograms) of eight sacks of cement were recorded as 20.5, 19.4, 19.6, 18.0, 21.0, 20.2, 20.4, and 20.9. (a) Find the mean and the median of...
-
Refer to Matthias Medical's financial statements, presented in Exercise 12-8. Required Calculate the following market measure ratios for 2013. a. Earnings per share (average of 418,000 shares...
-
What advancements in supramolecular chemistry have been instrumental in developing new classes of organocatalysts, and how do these developments influence catalytic efficiency and chiral induction ?
-
Write a paper proposal about History of east European Jewish immigrants. The proposal has two components. First, it includes a short description of what they plan to study, including a preliminary...
-
What is "disruptive change," and how is this different from "incremental change?" How does disruptive change affect an organization? What is a good example in a long-term care hospital? What...
-
3) Evaluate (5pts) 4) 23 x - 4 dx and 23 (x -4) dx. Compare your answers. Compute fx sin (x) cos (x) dx. a) Consider the substitution U= sin (x)? u = cos (x)? b) Consider the substitution ? (3pts)...
-
Andrew's business, after a harrowing first year of operations which saw him sustain a loss of P1,000,000, finally was able to generate a modest net taxable income of P250,000. In the next year, he...
-
5.2 Rewrite the following CISC-style program fragment so that it executes correctly on a RISC (load-store) processor that executes the GPR ISA outlined in the previous chapter. Assume that the GPR...
-
5. The following questions refer to the grammar shown below. S A AbBbAc AbaBB B AccBb | c a. Draw the parse tree for the sentential form bacBbcc. b. List all phrases in the sentential form bacBbcc....
-
3. Given the system y = y + y +1 y2 = y2 - ya 2 - 1 Let y= - () and let B be the box {(t, y)||t| 1, ]y| 2}. Determine the af(t,y) SK bounds M, K such that if(t, y)| M, dy;
-
Illini Company, Inc. Balance Sheet as of 12/31/20X0 Assets Current Assets: Cash $1,500,000 Accounts receivable, net 18,000 Inventory 50,000 Total current assets 1,568,000 Equipment 90,000 Goodwill...
-
Linda and Richard are married and file a joint return for 2012. During the year, Linda, who works as an accountant for a national airline, used $2,100 worth of free passes for travel on the airline;...
-
Scott Butterfield is self-employed as a CPA. He uses the cash method of accounting, and his Social Security number is 644-47-7833. His principal business code is 541211. Scott's CPA practice is...
-
How much of each of the following prizes or awards is taxable? a. Cheline received a $50,000 gift bag at the Oscars in 2012. b. Jon received a gold watch worth $350 for 25 years of service to his...
-
An analysis by Professor Peter M Rothwell and his colleagues (Nuffield Department of Clinical Neuroscience, University of Oxford, UK) published in 2012 in the medical journal The Lancet...
-
The following table shows the result of the 2018 General Elections in Pakistan, along with the vote share predicted by several organizations in the days before the elections. The sample sizes were...
-
The Chinese Academy of Sciences and the Chinese Academy of Environmental Planning conducted a survey of about 563 Chinese, with a tertiary education, about their interest in reducing global warming....
Study smarter with the SolutionInn App