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...
-
Using the Bohr model, estimate the energy of a Ka X-ray emitted by lead (Z = 82).
-
A study was carried out to compare the writing lifetimes of four premium brands of pens. It was thought that the writing surface might affect lifetime, so three different surfaces were randomly...
-
On a Sunday afternoon in 2005 at a busy hospital in the Pacific Northwest, computers started running slower and documents would not print. By Monday morning, the situation became worse as more...
-
A craftsman named Chuck Synovec builds two kinds of birdhouses, one for wrens and a second for bluebirds. Each wren birdhouse takes 4 hours of labor and 4 units of lumber. Each bluebird house...
-
Active listeners improve their evaluating activities by Question 1 3 options: forming an opinion before the presentation. organizing the information provided. clarifying the message. avoiding...
-
At the end of June, Rick Fontan decided to open his own computer service. Analyze the following transactions he completed by recording their effects in the expanded accounting equation. a. Invested...
-
Differential Analysis for a Lease-or-buy Decision Moffett Industries is considering new equipment. The equipment can be purchased from an overseas supplier for $3,140. The freight and installation...
-
Explain top down and bottom up method for costing. What tools can be used for Project cost analysis? What strategies can be implemented for managing costs in your project? Suggest one way you could...
-
Write the net force on each object in the picture below. Net force on A is (1) N, on B is (2) N, on C is (3) N, and on D is (4) N. 5 N 10 N A 10 N C 10 N B 10 N 15 N 5 N 15 N D Blank # 1 Blank # 2...
-
The balance of owner's capital at the beginning of the year was $50,000 and at the end of the year was $67,000. No additional capital was contributed during the year. Withdrawals were $23,000. What...
-
Explain pricing hard supply constraint product soft constraint product and no supply constrain product in hotel.
-
(a) Use the conversion factor 10 psi = 0.06895 MPa to convert 4360 psi to MPa. (Note: You must show step by step calculations to get a full mark.) (b) Use the conversion factors 1ft = 1728 inand 1...
-
Below is a pre-closing trial balance as of December 31, 2017: Debits Credits Accounts payable 6,800 Appropriations 160,000 Budgetary fund balance 38,000 Budgetary fund balance: reserve for...
-
The Home Depot is the leading retailer in the home improvement industry and one of the 10largest retailers in the United States. The company included the following on its January 29, 2012, balance...
-
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?
-
Determine the rate of return for Problem 17. Should your company purchase the dump truck? Data From Problem 17: 17. Your company is looking at purchasing a dump truck at a cost of $65,000. The truck...
-
Determine the incremental rate of return for Problem 19. Which track hoe should your company choose? Data From Problem 19: 19. Your company needs to purchase a new track hoe and has narrowed the...
-
Determine the incremental rate of return for Problem 20. Which track hoe should your company choose? Data From Problem 20: 20. Your company needs to purchase a new track hoe and has narrowed the...
Study smarter with the SolutionInn App