HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Problems
  2. /A year is a leap year when it divides exactly by 4, except that a year dividing by 100 is a leap…
HardComputer ScienceHigh School (9–10)Computer Science › ProgrammingNumericalIGCSE

A year is a leap year when it divides exactly by 4, except that a year dividing by 100 is a leap…

StemPy LabContributed by StemPy Lab

Try it on paper first. A hint, the key idea and the worked solution are here when you need them.

A year is a leap year when it divides exactly by 4, except that a year dividing by 100 is a leap year only if it also divides by 400. This program counts leap years.

pseudocode
FUNCTION IsLeap(Year : INTEGER) RETURNS BOOLEAN
    IF MOD(Year, 400) = 0
      THEN
        RETURN TRUE
    ENDIF
    IF MOD(Year, 100) = 0
      THEN
        RETURN FALSE
    ENDIF
    RETURN MOD(Year, 4) = 0
ENDFUNCTION

DECLARE Year : INTEGER
DECLARE Leaps : INTEGER
Leaps ← 0
FOR Year ← 1990 TO 2030
    IF IsLeap(Year)
      THEN
        Leaps ← Leaps + 1
    ENDIF
NEXT Year
OUTPUT Leaps

What does IsLeap return for 1900, 2000 and 2024? What is output?

Check your answer

Work it out on paper, then type your number. The answer itself stays hidden.

Need a reminder? The key ideaShowHide

DIV is the whole part of a division and MOD the remainder. ROUND(Value, Places) rounds to a number of decimal places, and RANDOM() returns a number from 0 to 1. LENGTH(Text) counts the characters, SUBSTRING(Text, Start, Length) takes a piece starting at Start (position 1 is the first character), UCASE and LCASE change the case.

The worked solution

Have you tried it?

Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.

Step 1. Three test years.

  • 1900 does not divide by 400, but it divides by 100, so IsLeap returns FALSE.
  • 2000 divides by 400, so it returns TRUE at once.
  • 2024 passes the first two tests and MOD(2024, 4) = 0, so it returns TRUE.

Step 2. The count. The years from 1990 to 2030 that divide by 4 are 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024 and 2028. The only century year, 2000, is a leap year. The output is 10.

Watch out. The order of the tests matters. Testing MOD(Year, 4) first would call 1900 a leap year.

Answer: FALSE, TRUE, TRUE, and the output is 10.

Log in to save this for later
← All Problems
← This program finds the average of three marks…This program works, but it is hard to maintain… →
More onComputer Science › Programming

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Library routines and string handlingProcedures, Functions and Strings in Pseudocode

More on this topic

  1. A long scenario question. A teacher has the names of 5 students in the file Names.txt, one name a…Hard
  2. Shopping.txt holds six lines: bread, rice, milk, eggs, tea and jam…Medium
  3. The file Best.txt holds one line: 120. What is output, and what does Best.txt hold afterwards, when…Easy
The nine squares of a board are input row by row: X, O, O, then X, X, X, then O, a dot for an empty…Hard
  • Three teams play three games each. Points[Team, Game] holds the points of a team in a game…Medium
  • All problems on this topic →