188k views
5 votes
5.20 LAB: Output values below an amount 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. Ex: If the input is: 5 50 60 140 200 75 100 the output is: 50,60,75,

User HHHH
by
4.3k points

1 Answer

1 vote

Answer:

Following are the code to the given question:

x= input()#defining a variable x that inputs value from the user-end

l = x.split(" ")#defining variable l that splits the x variable value with a space

t= int(l[len(l)- 1])#defining a variable t that decrease the l length and convert the value into integer

for i in range(1, (len(l) - 1)):#use for loop to calculate the range of the list

if int(l[i]) < t:#defining if block that checks the list value is lessthan t

print(l[i])#print list values

Output:

Please find the attached file.

Step-by-step explanation:

In the above-given code, an "x" variable is declared that inputs the value from the user-end, and use the "l" variable that splits all the value and defined a "t" variable that adds value into the list and convert the value into an integer.

In the next step, for loop is declared that counts the lists and use a conditional statement that checks list value is less than t and use the print the method that prints the list values.

5.20 LAB: Output values below an amount Write a program that first gets a list of-example-1
User Abdul Saleem
by
4.3k points