CS 170 Lab 5: Data Validation Loops
This is a lab exercise that involves using data validation loops to
get valid data from the user. In this case you will write code to
get a valid date from the user. This will be directly relevant
for your next programming assignment.
- Save the file validStart.py to your CS
170 directory.
- Launch Idle and use Open to begin editing this file. This file
has a set of functions that are designed to get a valid date (for
the years 1500 to 2400) from the user. Most of these functions are
implemented correctly. But the leapYear
and validDay functions are just stubs. Your job is to
correctly implement these functions so that only valid dates are
returned.
- As a few examples, the dates 1-26-1963, 2-29-2000, 9-30-1947,
2-29-2012 are valid. The dates 2-29-1900, 9-31-1947 and 2-30-2012
are invalid.
- The rule for leap year is that a year is a leap year if it is
evenly divisible by 4, unless it is evenly divisible by 100, unless
it is also divisible by 400. So, 1900 is NOT a leap year, but 1600
and 2000 are leap years.
- You are welcome to use as much code from this lab as you like
for your next program. I suggest that you use all of it.
- When your program is working properly you should print out a copy and hand it in. Make sure your printout has your name and Lab 05 prominently displayed on it. (Yes, we are back to printouts.)