2.2k views
5 votes
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 Then, get the last value from the input, which indicates a threshold. Output all integers less than or equal to that last threshold value. Assume that the list will always contain less than 20 integers. Ex: If the input is 5 50 60 140 200 75 100 the output is 50 60 75 The 5 indicates that there are five integers in the list, namely 50, 60, 140, 200, and 75. The 100 indicates that the program should output all integers less than or equal to 100, so the program outputs 50, 60, and 75. For coding simplicity, follow every output value by a space, including the last one. Such functionality is common on sites like Amazon, where a user can filter results.

User Obataku
by
6.2k points

1 Answer

3 votes

Final answer:

To solve this problem, you can use a simple Python program that takes the number of integers, the list of integers, and the threshold value as input. It then iterates through the list and outputs the numbers that are less than or equal to the threshold value.

Step-by-step explanation:

To solve this problem, you can use a simple Python program. First, you will take the number of integers from the input. Then, you will take the list of integers and the threshold value as input. Finally, you will iterate through the list and output the numbers that are less than or equal to the threshold value. Here's an example:

num_integers = int(input())
integer_list = [int(x) for x in input().split()]
threshold = int(input())

for num in integer_list:
if num <= threshold:
print(num, end=' ')

In this example, the program takes the number of integers as input, followed by the list of integers, and then the threshold value. It then iterates through the list of integers and prints the numbers that are less than or equal to the threshold value.

To run this program, you can copy the code into a Python IDE or text editor and then execute it. Make sure you enter the inputs correctly according to the specified format. For example, if the input is '5 50 60 140 200 75 100', the program will output '50 60 75'.

User Marcodor
by
7.0k points