1. Consider a sequence of numbers that starts with 5 and 7, where each subsequent number...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Consider a sequence of numbers that starts with 5 and 7, where each subsequent number is obtained as follows: if the current number is even, the next number is the sum of the current and previous number; if the current number is odd, the next number is obtained by adding 3 to the current number. For example: The first two numbers are 5 and 7. The current number is 7 (odd), so the new number is 7 + 3 = 10. The current number is 10 (even), so the new number is 10 + 7 = 17. Write a Python program that prompts the user to enter a specific target sequence length (which should be a positive non-zero integer). The program should then call a user-defined recursive function to calculate the sequence numbers and print the sequence along with its sum, as demonstrated in the following sample output: Enter a positive non-zero integer as the target length : -5 Target number must be a positive non-zero integer. Please enter a nonzero positive integer: 0 Target number must be a positive non-zero integer. Please enter a nonzero positive integer: 10 The sequence with length of (10) is: 5 7 10 17 20 37 40 77 80 157 The sum of this sequence= (450) 1. Consider a sequence of numbers that starts with 5 and 7, where each subsequent number is obtained as follows: if the current number is even, the next number is the sum of the current and previous number; if the current number is odd, the next number is obtained by adding 3 to the current number. For example: The first two numbers are 5 and 7. The current number is 7 (odd), so the new number is 7 + 3 = 10. The current number is 10 (even), so the new number is 10 + 7 = 17. Write a Python program that prompts the user to enter a specific target sequence length (which should be a positive non-zero integer). The program should then call a user-defined recursive function to calculate the sequence numbers and print the sequence along with its sum, as demonstrated in the following sample output: Enter a positive non-zero integer as the target length : -5 Target number must be a positive non-zero integer. Please enter a nonzero positive integer: 0 Target number must be a positive non-zero integer. Please enter a nonzero positive integer: 10 The sequence with length of (10) is: 5 7 10 17 20 37 40 77 80 157 The sum of this sequence= (450)
Expert Answer:
Answer rating: 100% (QA)
Heres the corrected Python program with comments explaining each part of the code Define a recursive ... View the full answer
Related Book For
Finite Mathematics and Its Applications
ISBN: 978-0134768632
12th edition
Authors: Larry J. Goldstein, David I. Schneider, Martha J. Siegel, Steven Hair
Posted Date:
Students also viewed these programming questions
-
The main difference between management and stewardship lies in their underlying ethos and approach. Management is like running a business efficiently to make profits, while stewardship is more about...
-
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...
-
On Apr 5, 2021 Carter was in Omaha, Nebraska attending a seminar and was a guest at the Blue beiger Inn. At the end of the first day of the seminar, Carter took a swim in the motel's pool. Following...
-
A driver of a car is initially 455 miles from home, traveling toward home on a straight freeway at 70 miles per hour. (a) Write a formula for a linear function f that models the distance between the...
-
When is the general journal used in a manual accounting information system? Provide some examples of transactions that would be recorded in the general journal.
-
A shipping specialist at a craft store needs to pack Styrofoam balls of radius 4.00 in. into a 1.40 ft x 2.80 ft x 1.40 ft rectangular cardboard container. What is the maximum number of balls that...
-
The degrees of freedom at the triple point will be (a) 0 (c) 2 (b) 1 (d) 3 .
-
The following selected transactions were completed by Niles Co. during March of the current year: Mar. 1. Purchased merchandise from Haas Co., $43,250, terms FOB shipping point, 2/10, n/eom. Prepaid...
-
Sheldon saw the same commercial that Leonard saw in Leonard v. Pepsico, Inc. He wanted the Pepsi leather jacket for 1,450 Pepsi pointswhich he could earn by purchasing 1,450 individual Pepsi bottles...
-
Consider a coal plant with the following characteristics: Capital cost of $3300 per kW CCF of 0.13 FOM costs of $103 per kW-year Fuel costs of $1.07 per GJ Utilization of 72% (about 6312 hours per...
-
On August 1 , Cairle Company s work - in - process inventory consisted of three jobs with the following costs: Job 7 0 Job 7 1 Job 7 2 Direct materials $ 1 , 7 0 0 $ 2 , 0 0 0 $ 8 5 0 Direct labor 1...
-
Why might companies and investment funds engage in greenwashing?
-
What are the main differences between a linear economy and a circular economy?
-
What do we mean by the term carbon footprint and what are its two components?
-
Oscar (age 70) and Maggie (age 60) were married and jointly owned a personal residence valued at $3,800,000 when Oscar died in 2017. Oscar also owned stocks valued at $4,700,000; an art collection...
-
Why is it important for businesses to promote a diverse, equitable, and inclusive workforce in their operations at home and abroad?
-
Bonucci Corporation acquires 80 percent of Verratti Corporation for $41,000,000 on January 1, 2016. At the time of acquisition, Verratti has total net assets with a fair value of $25,100,000. For the...
-
Which, if any, of the dichloroethene molecules drawn in Data Table II (3.) (4.) and (5.) are geometric isomers? A. B. C. D. cis-1,2-dichloroethene and trans-1,2-dichloroethene...
-
A corporation has a plastics division and an industrial equipment division. For each $1 worth of output, the plastics division needs $.02 worth of plastics and $.10 worth of equipment. For each $1...
-
In 2006, Emma purchased a house and took out a 25-year, $50,000 mortgage at 6% interest compounded monthly. In 2016, she sold the house for $150,000. How much money did she have left after she paid...
-
Consider a 25-year mortgage of $380,000 at 6.9% interest compounded monthly, where the loan is interest-only for 10 years. What is the monthly payment during the first 10 years? Last 15 years?
-
True or False. The loss coefficient denotes the energy dissipated per radian per unit strain energy.
-
True or False. The hysteresis loop of the stress-strain curve of a material causes damping.
-
True or False. Motion in the case of hysteresis damping can be considered harmonic.
Study smarter with the SolutionInn App