Print all the numbers which are less than given key element from a given list.

Python Program to get an element and print the elements of list which is lesss than the element.

Sample Input 1:

5 5 7 9 3 1 4

Sample Output 1:

3 1

Sample Input 2:

5 5 7 9 3 1 8

Sample Output 2:

5 7 3 1

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#write your code here

Program or Solution

l=list(map(int,input("Enter array elements:").split(" ")))
e=int(input("Enter a number:"))
for i in range(0,len(l)):
        print(l[i],end=" ")


Program Explanation

Input: To get list of numbers seprated by space, use split(" ") method.

Split() method splits the numbers as seprate elements.

By default this methods are considered as string, since input() method returs string. Use map() function to convert all elements as integer and store it in list.

Process: using for loop visit each location sequentially from 1 to len(l)-1. if the value located in a postion is lesser than the element given by user, then print the value using print statement.