57.4k views
8 votes
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).

User TLD
by
5.1k points

2 Answers

9 votes

Answer:input_numbers = [int(x) for x in input().split(' ')]

input_range = [int(x) for x in input().split(' ')]

for number in input_numbers:

if input_range[0] <= number <= input_range[1]:

print('{}'.format(number), end = ' ')

Step-by-step explanation:

User Balasubramanian S
by
5.6k points
8 votes

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=" ")

Step-by-step 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=" ")

User Boardernin
by
5.4k points