Write a program that first gets a list of integers from input. 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).

Respuesta :

Answer:

The program in Python is as follows:

mylist = []

num = int(input("Length: "))

for i in range(num):

    inp = int(input(": "))

    mylist.append(inp)

lower = int(input("Lower Bound: "))

upper = int(input("Upper Bound: "))

for i in mylist:

    if i >= lower and i <= upper:

         print(i, end=" ")

Explanation:

This initializes an empty list

mylist = []

The prompts the user for length of the list

num = int(input("Length: "))

The following iteration reads input into the list

for i in range(num):

    inp = int(input(": "))

    mylist.append(inp)

This gets the lower bound of the range

lower = int(input("Lower Bound: "))

This gets the upper bound

upper = int(input("Upper Bound: "))

This iterates through the list

for i in mylist:

This checks for elements of the list within the range

    if i >= lower and i <= upper:

This prints the list element

         print(i, end=" ")