a) We'll say that a pair in a list L is two instances of a number...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
a) We'll say that a "pair" in a list L is two instances of a number separated by another number. So, in (5, 7, 5) the 5's make a pair. Pairs can overlap, so (5, 10, 5, 10, 5) contains 3 pairs - two pairs for 5 and one pair for 10. Write a function called countPairs(t) that takes as an input a list of integers L and returns the number of pairs in the list. Test program/output: print (count Pairs ([5, 7, 5])) print (count Pairs (15. 10. 5. 10. 5))) print (count Pairs ((6))) print (count Paira (())) print (count Pairs ([3, 3, 3. 4, 3, 4])) b) An "extended pair" in a list L is two instances of a number separated by t consecutive numbers. For example, in the list (5. 7, 6, 5, 3, 6, 7) the 5's and the 6's make an extended pair for t = 2. That is, the 5's are separated by 2 elements and the 6's are separated by 2 elements. Also, in the same list, the 7's make an extended pair for t= 4. Similar to part (a), pairs can overlap. For example, for t = 2, the list [5, 7, 6, 5, 7, 6, 5, 7. 6. 3, 71 contains 7 pairs - two pairs for 5. three pairs for 7 and two pairs for 6. Write a function called count ExtendedPairs (L, t) that takes as an input a list L and an integer t. The function should return the number of extended pairs in L that are separated by t elements. Test program/output: print (count ExtendedPairs ([5, 7, 5), 2)) print (count ExtendedPairs([5, 7, 6, 5, 3, 6, 7). 2)) print (count ExtendedPairs({5, 7, 6, 5, 3, 6, 7], 4)) print (count ExtendedPairs ([5, 7, 6, 5, 7, 6, 5, 7, 6, 3, 7], 2)) 0217 7 c) Bonus - 10 points (out of the 35 pts). Given a list L, write a function getMaximumPairs (L) that returns two integers t and n, where t is the integer that maximizes the number of extended pairs and n is the maximum number of extended pairs. 2 The functions in parts (a), (b) and (c) should be submitted in the same Python file/script and not as separate files. a) We'll say that a "pair" in a list L is two instances of a number separated by another number. So, in (5, 7, 5) the 5's make a pair. Pairs can overlap, so (5, 10, 5, 10, 5) contains 3 pairs - two pairs for 5 and one pair for 10. Write a function called countPairs(t) that takes as an input a list of integers L and returns the number of pairs in the list. Test program/output: print (count Pairs ([5, 7, 5])) print (count Pairs (15. 10. 5. 10. 5))) print (count Pairs ((6))) print (count Paira (())) print (count Pairs ([3, 3, 3. 4, 3, 4])) b) An "extended pair" in a list L is two instances of a number separated by t consecutive numbers. For example, in the list (5. 7, 6, 5, 3, 6, 7) the 5's and the 6's make an extended pair for t = 2. That is, the 5's are separated by 2 elements and the 6's are separated by 2 elements. Also, in the same list, the 7's make an extended pair for t= 4. Similar to part (a), pairs can overlap. For example, for t = 2, the list [5, 7, 6, 5, 7, 6, 5, 7. 6. 3, 71 contains 7 pairs - two pairs for 5. three pairs for 7 and two pairs for 6. Write a function called count ExtendedPairs (L, t) that takes as an input a list L and an integer t. The function should return the number of extended pairs in L that are separated by t elements. Test program/output: print (count ExtendedPairs ([5, 7, 5), 2)) print (count ExtendedPairs([5, 7, 6, 5, 3, 6, 7). 2)) print (count ExtendedPairs({5, 7, 6, 5, 3, 6, 7], 4)) print (count ExtendedPairs ([5, 7, 6, 5, 7, 6, 5, 7, 6, 3, 7], 2)) 0217 7 c) Bonus - 10 points (out of the 35 pts). Given a list L, write a function getMaximumPairs (L) that returns two integers t and n, where t is the integer that maximizes the number of extended pairs and n is the maximum number of extended pairs. 2 The functions in parts (a), (b) and (c) should be submitted in the same Python file/script and not as separate files.
Expert Answer:
Answer rating: 100% (QA)
Here is the implementation for the given tasks python def countPairsL if not L or lenL 2 ... 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
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
On 1 June 2019, Manchester United Ltd bought 48 million ordinary shares in Chelsea FC Ltd paying GHS 280 million cash. The summarised statement of financial position for the two entities as at 31...
-
Chihooly Glass Products Ltd. is a leading provider of bottles for the brewing industry. Suppose the company recently reported these figures: Required Evaluate Chihooly Glass's operations during 2017...
-
Describe why there is pressure on the price to fall when P < ATC. Is there a long- and short-run distinction in the answer?
-
To compute the Global Warming Potential of a refrigerant (a) HFC-134a is used as a reference gas (b) Hydrocarbon is used as a reference gas (c) \(\mathrm{CO}_{2}\) is used as a reference gas (d)...
-
Preparing lessees journal entries for an operating lease and a capital lease. General Motors Corporation (GM) sells a luxury minivan for $25,000. FedUp Delivery Services agrees to lease a minivan for...
-
ances Rundle Manufacturing Company was started on January 1, 2018, when it acquired $76,000 cash by Issuing common stock. Rundle Immediately purchased office furniture and manufacturing equipment...
-
The Morton Ward Company is considering the introduction of a new product that is believed to have a 50-50 chance of being successful. One option is to try out the product in a test market, at an...
-
What effect would a decrease in interest rates by the Federal Reserve most likely have in the nation's manufacturing sector all other factors remaining constant ?
-
Does a higher p/e ratio tell you that the investing public is optimistic or pessimistic about a company's future growth potential? Why? Use Figure 12.1 Figure 12.1 Growth of $100 Invested in...
-
1. (a) (b) (c) 2. (a) (b) Define data structures? What are the objectives of studying data structures? Explain deletion operation for queue with algorithm. Consider the following array A with five...
-
Use the same circuit as part (a) (repeated below). Assuming the diode has a constant voltage drop of 0.7V, sketch Vout versus time for the triangular wave input shown below, and answer the questions....
-
I have attempted to complete but I am confused with the receipts with how to get april though dec. Would it be possible to look at what I got so far and let me know? If you see anything else please...
-
The following circuit uses the Op Amp TL081. The open-loop transfer function is shown in the plot below Vout Rf 4 R Vin with AVD-Large-Signal Differential Voltage Amplification 106 105 104 103 10 101...
-
Let CB-A = CA = 4-[143] A = 5 3 If possible, compute the following. If an answer does not exist, enter DNE. help (matrices) help (matrices) B = C = 5 - -3 2 1 -2 3 -3
-
H Corporation has a bond outstanding. It has a coupon rate of 8 percent and a $1000 par value. The bond has 6 years left to maturity but could be called after three years for $1000 plus a call...
-
In 2012, Lou has a salary of $54,000 from her job. She also has interest income of $1,700. Lou is single and has no dependents. During the year, Lou sold silver coins held as an investment for a...
-
Sherry Hopson owns a retail family clothing store. Her store is located at 4321 Circle Drive, Houston, TX 77001. Her employer identification number is 95- 1234321 and her Social Security number is...
-
In the 2012 tax year, Michelle paid the following amounts relating to her 2010 tax return: Tax deficiency..........................................$5,000 Negligence...
-
Ideally the ______________ phase of the systems development from the phases given below requires maximum efforts. (a) Testing (b) Documentation (c) Feasibility checking (d) All of these
-
A conducting loop having radius \(20 \mathrm{~cm}\) is held fixed, and there is a magnetic flux of \(0.6 \mathrm{~T} . \mathrm{m}^{2}\) through the loop. When the magnetic field is turned off, the...
-
To measure the magnitude of Earth's magnetic field \(B_{E}\), you use a single conducting coil with an area \(A=10 \mathrm{~cm}^{2}\) rotating at an angular speed \(\omega\), and measure the peak emf...
Study smarter with the SolutionInn App