Answer:
- myList = []
- num = int(input("Enter a number: "))
-
- while(num != -1):
- myList.append(num)
- num = int(input("Enter a number: "))
-
- output = ""
- for i in range(0, len(myList) - 2):
- lastIndex = len(myList) - 1
- secondLastIndex = len(myList) - 2
- if(myList[i] >= myList[secondLastIndex] and myList[i] <= myList[lastIndex]):
- output += str(myList[i]) + " "
-
- print(output)
Explanation:
The solution is written in Python 3.
Firstly, create a list to hold the user input of integers.
Next, use input function to prompt user to enter integer and assign it to num
While the input num is not -1, keep prompting the user to input number and add it to myList (Line 4 - 6)
Create a output string variable (Line 8)
Create a for loop to traverse through the first element to third last of the element because the last two elements are bounds (Line 9).
Get the last and second last index (Line 10 -11)
Create an if statement to check the current element is within the lower bound and upper bound. If so, join the element to output string (Line 12 - 13).
After the loop, print the output string (Line 15).