The following program is supposed to accept an integer as user input. That input is used to define a limit.
The program then looks through a sorted list and finds the position of the first number that is greater than that limit.
It then outputs the position.
If there is no number larger than the user's input, it outputs Not found.
For example, if the input is 28, the output should be as follows:
Enter a value: 28
(6, 7, 11, 21, 50, 64)
Found at position: 3
and if the input is 64, the output should be as follows:
Enter a value: 64
(6, 7, 11, 21, 50, 64)
Not found.
There are five (5) errors in the following program that prevent it from doing what it is supposed to do. Your task is to find and fix those 5 errors
and then write the code that should appear on that line to make the code work as intended.
1. limit = int(input("Enter a value: "))
2.
3. listi = [6, 21, 11, 7, 64, 58]
4. sorted(listi)
5. print(listi)
6.
7. value = -1
8.
9. for position in len(listi):
10. if listi[position] > limit and found:
11.
12.
13.
found = True
value = position
14. if value == -1:
15. print('Found at position: {}.'.format(value))
16. else:
17. print('Not found.')
18.