Question: Lab Questions 1. Write a Python program stored in a file L4q1.py that: A. Gets a number as an input from the user and stores

Lab Questions 1. Write a Python program stored in a file L4q1.py that: A. Gets a number as an input from the user and stores it in a variable. That number represents the length of a list. The program should then keep prompting until the user enters a valid number which is less than 10, and greater than 2. B. Creates a list where the user enters each entry in the list (explicitly convert each entry to type int). An entry is considered valid only if it is strictly greater than 0. If the entry is not valid, then the program should re-run from the invalid entry index, until valid entries are entered by the user. C. Gets a target number as an input from the user, and prints any two distinct list entries (values and indices) whose sum is equal to the target number. If no such entries are found then it should print a message stating that fact. Sample Output #1: 1. ********** *********Section A********* WWWWW 2. Enter the length: 2 3. Invalid list length, try again. 4. 5. Enter the length: 0 6. Invalid list length, try again. 7. 8. Enter the length: 5 9. The list contains 5 entries. 10. 11. ************* ***********Section B************************* 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. 1. 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 C*********** ******** 25. Enter the target value: 10 26. The entries 4, 6 found at index 0, 2 sum to 10. 27. 28. ********* ********************* Sample Output #2: 1. ** ***** ***********Section A************************* 2. Enter the length: 3 3. The list contains 3 entries. . 4. 5. ********* 3 *****Section B******************* ********* 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. 10. ******* **Section C******** 11. Enter the target value: 8 12. No valid combination summing to 8 was found. 13. ******** ***********
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
