Ask Question
2 August, 12:08

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

+4
Answers (1)
  1. 2 August, 16:04
    0
    numList = [] length = int (input ("Enter a number: ")) numList. append (length) for i in range (0, length) : num = int (input ("Enter a number: ")) numList. append (num) lowerBound = int (input ("Enter a number: ")) numList. append (lowerBound) upperBound = int (input ("Enter a number: ")) numList. append (upperBound) output = "" for i in range (1, len (numList) - 2) : if (numList[i] > = lowerBound and numList[i] < = upperBound) : output + = str (numList[i]) + " " 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).
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “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 ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers