Python Practice › Set Programs › Program 18

Are all elements even?

EasySet Programs · 18 of 48

Write a Python program to check whether all elements of a set are even.

Advertisement
Input
{2, 4, 6}, {2, 3}
Output
{2, 4, 6} True
{2, 3} False

Approach

  1. all(x % 2 == 0 for x in s).

Solution

Python
for s in [{2, 4, 6}, {2, 3}]:    print(s, all(x % 2 == 0 for x in s))
Output
{2, 4, 6} True
{2, 3} False

Learn the concept

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

More set programs

← All 48 Set Programs

Leave a Comment