8,307 views
35 votes
35 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 fewer than 20 integers.

Ex: If the input is
5 50 60 140 200 75 100

the output is
50 60 75

User SystemParadox
by
2.6k points

1 Answer

14 votes
14 votes

Answer:

The program in Python is as follows:

num = int(input())

numList = []

for i in range(num+1):

numInput = int(input())

numList.append(numInput)

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

if numList[i] <= numList[-1]:

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

Step-by-step explanation:

This gets input for the number of integers

num = int(input())

This initializes an empty list

numList = []

This iterates through the number of integers and gets input for each

for i in range(num+1):

numInput = int(input())

The inputs including the threshold are appended to the list

numList.append(numInput)

This iterates through the list

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

All inputs less than or equal to the threshold are printed

if numList[i] <= numList[-1]:

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

User Tixxit
by
2.7k points