Python Practice › List Programs › Program 20

Elements divisible by 3 and 7

EasyList Programs · 20 of 100

Write a Python program to get all elements divisible by both 3 and 7.

Advertisement
Input
[21, 14, 63, 9, 42, 50]
Output
[21, 63, 42]

Approach

  1. Divisible by both 3 and 7 means divisible by 21.

Solution

Python
numbers = [21, 14, 63, 9, 42, 50]print([n for n in numbers if n % 3 == 0 and n % 7 == 0])
Output
[21, 63, 42]

Learn the concept

New to this topic? Read the lesson, then come back.

More list programs

← All 100 List Programs

Leave a Comment