[Solved] Filter Events Problem with Python

Filter Events: Write a program to get size of list and its elements and  to find numbers divisible by thirteen from a list using anonymous function (Lambda) and display those numbers.

Input Format:
The first line of input corresponds to the size of list ‘n’.
The next ‘n’ line of input corresponds to the elements in the list .

Output Format:
The output consists of numbers divisible by thirteen separated by space.
Refer sample output for formatting specifications.
 

Problem Constraints:
n > 0 print the numbers divisible by thirteen separated by space, else display as “Invalid input“.

Sample Input/Output 1:
Enter size of list
9
Enter the elements in list
12
65
54
39
102
339
221
50
70

65 39 221

Sample Input/Output 2:
Enter size of list
O
Invalid input
 


Additional Sample TestCases

Sample Input and Output 1 :

Enter size of list0
Invalid input

Sample Input and Output 2 :

Enter size of list9
Enter the elements in list
12
65
54
39
102
339
221
50
70
65 39 221

Problem Requirements:

Python3

KeywordMin CountMax Count
lambda1

Write a program to get size of list and its elements and  to find numbers divisible by thirteen from a list using anonymous function (Lambda) and display those numbers.

Input Format:
The first line of input corresponds to the size of list ‘n’.
The next ‘n’ line of input corresponds to the elements in the list .

Output Format:
The output consists of numbers divisible by thirteen separated by space.
Refer sample output for formatting specifications.
 

Problem Constraints:
n > 0 print the numbers divisible by thirteen separated by space, else display as “Invalid input“.

Sample Input/Output 1:
Enter size of list
9
Enter the elements in list
12
65
54
39
102
339
221
50
70

65 39 221

Sample Input/Output 2:
Enter size of list
O
Invalid input
 


Additional Sample TestCases

Sample Input and Output 1 :

Enter size of list0
Invalid input

Sample Input and Output 2 :

Enter size of list9
Enter the elements in list
12
65
54
39
102
339
221
50
70
65 39 221

Solution

n = int(input("Enter size of list\n"))
# fill your code here

if n > 0:
    l = []
    print("Enter the elements in list")
    for i in range(n):
        l.append(int(input()))
    l = list(filter(lambda x: x % 13 == 0, l))
    print(*l)
else:
    print("Invalid input")
    

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *