First Summer 2006


Lecture Notes Seven: Decisions in Python.
We will first discuss the problem of yesterday.

We then discuss this problem (whose number was 10, once, in a list of problems):

10. A year with 366 days is called a leap year.

A year is a leap year if

  • it is divisible by 4 (for example, the year 1980),
  • except it is not a leap year if it is divisible by 100 (for example, the year 1900);
  • however, it is a leap year if it is divisible by 400 (for example, the year 2000).

There were no exceptions before the introduction of the Gregorian calendar on October 15, 1582 (for example, the year 1500 was a leap year).

Write a program (called Ten) that asks the user for a year and computes whether that year is a leap year or not.

Here's a sample run of such a program:

frilled.cs.indiana.edu%java Ten

Please enter the year then press Enter : 1500
Leap year: 1500
frilled.cs.indiana.edu%java Ten
Please enter the year then press Enter : 1900
1900 not a leap year!
frilled.cs.indiana.edu%java Ten
Please enter the year then press Enter : 1996

Leap year: 1996
frilled.cs.indiana.edu%java Ten
Please enter the year then press Enter : 1997
1997 not a leap year!
frilled.cs.indiana.edu%java Ten
Please enter the year then press Enter : 2000
Leap year: 2000
frilled.cs.indiana.edu%

We will develop a program in Python, of course.


Last updated: May 17, 2006 by Adrian German for A201/A597