9.16 LAB: Elements in a range Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. That list is followed by two more integers representing lower and upper bounds of a range. Your program should output all integers from the list that are within that range (inclusive of the bounds). For coding simplicity, follow each output integer by a space, even the last one

Respuesta :

Answer:

  1. numList = []
  2. length = int(input("Enter a number: "))  
  3. numList.append(length)
  4. for i in range(0, length):
  5.    num = int(input("Enter a number: "))
  6.    numList.append(num)
  7. lowerBound = int(input("Enter a number: "))
  8. numList.append(lowerBound)
  9. upperBound = int(input("Enter a number: "))
  10. numList.append(upperBound)
  11. output = ""
  12. for i in range(1, len(numList) - 2):
  13.    if(numList[i] >= lowerBound and numList[i] <= upperBound):
  14.        output += str(numList[i]) + " "
  15. print(output)

Explanation:

The solution is written in Python 3.

Firstly create a list to hold a list of input (Line 1).

Prompt user to enter the number of desired integer and add it to the numList (Line 3- 4).

Create a for-loop that loop for length times and prompt user to enter a number and add it to numList repeatedly (Line 6 -8).

Next, prompt user to input lowerBound and upperBound and add them as the last two elements of the list (Line 10 - 14).

Create an output string (Line 16) and create another for loop to traverse through the numList from second element to third last elements (Line 18). if the current value is bigger to lowerBound and smaller than upperBound then add the current value to the output string.

At last, print the output string (Line 22).

The program is an illustration of loops.

Loops are used to perform repetitive operations.

The program in Python, where comments are used to explain each line is as follows:

#This defines an empty list

numList = []

#This gets the length of input, and appends it to the list

n1 = int(input()); numList.append(n1)

#This gets the lower bound, and appends it to the list

n2 = int(input()); numList.append(n2)

#This gets the upper bound, and appends it to the list

n3 = int(input()); numList.append(n3)

#The following iteration gets input for the list

for i in range(n1):

   numList.append(int(input()))

#The following iteration prints the inputs that are within the boundary    

for i in range(3,len(numList)-1):

  if(numList[i] >= n2 and numList[i] <= n3):

      print(numList[i],end = " ")

Read more about similar programs at:

https://brainly.com/question/13707877