Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I want to write a program that will check if each number in a list is evenly divisible by 25. I have executed the below code:

n = [100, 101, 102, 125, 355, 275, 435, 134, 78, 550]

for row in rows:

    if n / 25 == an evenly divisible number:

        row.STATUS = "Major"

    else:

        row.STATUS = "Minor"

Kindly guide me.

1 Answer

0 votes
by (108k points)

For achieving your goal, you can simply use the modulo operator:

for row in rows:

    if n % 25:

        row.STATUS = "Minor"

    else:

        row.STATUS = "Major"

or you can also use the below code:

for row in rows:

    row.STATUS = "Minor" if n % 25 else "Major"

#n % 25 means "Give me the remainder when n is divided by 25".

If you are a beginner and want to know more about Python, then do refer to the Python certification course. 

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 17, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...