Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with the following code.. Sample Output #1: 1. 2. Enter the length: 2 3. Invalid list length, try again. 4. 5. Enter

Please help me with the following code..

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Sample Output #1: 1. 2. Enter the length: 2 3. Invalid list length, try again. 4. 5. Enter the length: 0 6. Invalid list length, try again. 7. B. Enter the length: 5 9. The list contains 5 entries. 10. 12. Enter the entry at index 0: 4 13. Enter the entry at index 1: 5 14. Enter the entry at index 2: -1 15. Invalid entry at index 2. 16. 17. Enter the entry at index 2: 6 18. Enter the entry at index 3: -8 19. Invalid entry at index 3. 20. 21. Enter the entry at index 3: 5 22. Enter the entry at index 4: 3 23. 24 . # # # # # # # # # ### #### ## Section (*##10 25. Enter the target value: 10 26. The entries 4. 6 found at index 0. 2 sum to 10. 27. Sample Output #2: 1. 2. Enter the length: 3 3. The list contains 3 entries. 5. 6. Enter the entry at index 0: 2 7. Enter the entry at index 1: 4 8. Enter the entry at index 2: 5 9. 1 1. Enter the target value: 8 12. No valid combination summing to 8 was found.2. Fibonacci Sequence. Fibonacci numbers are numbers in a sequence, where cach number is the sum of the two previous numbers. Starting with 0 and 1, Fibonacci sequence goes like 1, 1, 2, 3, 5, 8, 13 etc. Write a Python program stored in a file L4q2.py that asks for a starting number and an ending number, and then prints all the Fibonacci numbers between them (and including the starting and ending numbers, if they are also Fibonacci numbers). Each Fibonacci number, must be separated by a space. Example #1. The user enters start and end numbers (lines 2-3). The program then outputs the total number of Fibonacci numbers within range, along with the numbers. Sample output 2. Enter starting number: 5 Enter ending number: 560 4. 5. The 10 Fibonacci numbers between 5 and 500 are: 6. 5 8 13 21 34 55 89 144 233 377 7. Example #2. The user enters start and end numbers (lines 1-2). The program then outputs the total number of Fibonacci numbers within range, along with the numbers. Sample output 1. 2. Enter starting number: 55 Enter ending number: 999 4. 5. The 7 Fibonacci numbers between 55 and 999 are: 6. 55 89 144 233 377 610 9873. Write a Python program stored in a file L4q3. py that: . Gets single-digit numbers from the user on one line (digits are separated by white space) and adds them to a list. The first digit and the last digit should not be a zero. If the user provides an invalid entry, the program should prompt for a new value. Converts every entry in the list to an integer and prints the list. The digits in the list represent a non- negative integer. For example, if the list is [4,5,9,1], the entries represent the integer 4591. The most significant digit is at the zeroth index of the list. Adds the integer that the reversed value of the integer. For example, if the list is [4,5,9,1], the addition will be 4591 + 1954 = 6545 and the resulting list will be [6,5,4.5] Sample Output#1: 1. 2. Enter single digits separated by one space: 0 5 1 1 3. Invalid list, try again. 4. 5. Enter single digits separated by one space: 8 5 9 0 6. Invalid list, try again. 7. 8. Enter single digits separated by one space: 0 58 1 14 9. Invalid list, try again. 10 11. Enter single digits separated by one space: 4 5 9 1 12. The initial list is: [4,5,9,1] 13. The reversed list is: [1,9,5,4] 14. The addition list is: [6,5,4,5] Sample Output#2: 2. Enter single digits separated by one space : 9 9 9 9 2 3. The initial list is: [9,9,9,9,2] 4. The reversed list is: [2,9,9,9,9] 5. The addition list is: [1, 2,9,9,9,1]4. Write a Python program stored in a file L4q4.py that that takes a string variable as input from the user and prints the length of the entry on the next line. If the length of the entry is even, print all the characters that are in the even position. If the length of the entry is odd, print all the characters that are in the odd position. Add an empty line. On the following line, print the index of each character under the corresponding character. Sample output #1: Print one full line of * on line 1. At the prompt, the user enters "Texas A&M University" (line 2). The program outputs the length of input on line 3 (even). Line 4 is blank and on line 5 all the characters in the even positions are printed. The corresponding index of each character is printed below them on line 6 and one full line of * is printed on line 7. 2. Enter a string variable: Texas A&M University 3. Length of the string Texas A&M University is 20 5. T M U S t 6. 0 2 10 12 14 16 18 7. Sample output #2: Print one full line of * on line 1. At the prompt, the user enters "Howdy! Good Luck." (line 2). The program outputs the length of input on line 3 (odd). Line 4 is blank and on line 5 all the characters in even positions are printed. The corresponding index of each character is printed below them on line 6 and one full line of * is printed on line 7. 2. Enter a string variable: Howdy! Good Luck. 3. Length of the string Howdy! Good Luck. is 17 4. U k 1 3 9 11 13 15 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

=+ b. What are intragovernmental holdings?

Answered: 1 week ago