Decision Control

Your Assignment

Decisions, decisions, decisions. Computers are terrible at them, so as programmers we need to instruct them on how to make good ones. In this lab you will write a program that accepts a date in the form “month/day/year” and prints whether or not the date is valid. For example 5/24/1962 is valid, but 9/31/2000 is not. (September has only 30 days.)

Your program, in order to be correct, should be able to pass these simple (but far from complete!) test cases:

  • 2/29/2000 - valid
  • 2/29/2001 - not valid
  • 4/30/1984 - valid
  • 4/31/1984 - not valid
  • 0/12/1234 - not valid
  • 13/30/2014 - not valid
  • 10/24/2014 - valid

Generally speaking, I want to see the following structure in your program. This encourages “seperation of concerns”:

  1. Obviously, you will be using if-elif-else statements to make
    decisions in your program.
  2. The function main() should print a friendly message and ask for the input of the date in the required format (see above). It then should parse the date into its day, month and year components. It will pass this information to a “date check” function.
  3. A “date check” function needs to be defined that will take these date components of day, month and year and checks to see if that date is valid.
    • This function is required to return a Python True or False boolean value (reflecting a valid, or invalid date, respectively) that your main() function will use to print out the correct message about the date’s validity.
  4. A function that calculates leap year needs to be used by your date check function. This formula should be easy to look up.
    • You need to write this function that takes takes a year as a parameter that will then return a Python True or False boolean value (reflecting a leap, or non-leap year, respectively).

Sample output looks like:

This program accepts a date in the form month/day/year and outputs whether or not the date is valid
Please enter a date (mm/dd/yyyy): 2/29/2000
2/29/2000 is valid


This program accepts a date in the form month/day/year and outputs whether or not the date is valid
Please enter a date (mm/dd/yyyy): 4/31/1984
4/31/1984 is not valid

Submission Requirements

There are a few standards to adhere to when submitting your lab. Please read, and follow them carefully.

  1. Submission Filename: Submit a file named

  2. Documentation String (“docstring”): The following docstring (properly edited with your name) needs to be the very first thing in your Python program file.

    """CSC 161 Lab: Decision Control
    This lab...
    Fox Mulder
    Lab Section TR 2:00-3:15pm
    Fall 2015

    Read more about docstrings: Program Documentation String

  3. Comments (lines prefaced with #): Unclear parts of your code can receive point deductions, so be judicious about using comments. Do not overuse comments. Too much unnecessary commenting can complicate reading otherwise clear code!

    Read more about comments: Program Comments

  4. Python Code Style: You will need to run your Python program file through the online PEP 8 style checker found in CSC 161 Style.

The Blackboard post for this lab assignment will contain the details regarding the due date and other details regarding class administration for this assignment.


The following is the grading rubric for this lab to be used by the course graders. The lab is worth 100 points.

Reasonable variations of this lab should be acceptable. In particular, we would accept programs that take input files with different formats (comma separated, space separated, one number per line, …)

Here’s a brief grading rubric:
  • Syntax errors: -30 points
  • A bad/missing docstring (i.e. no name, lab section, etc): -10 points
  • Missing main() function: -10 points
  • Code doesn’t attempt to adhere to Python coding style: -10 points
  • The submitted filename is wrong: -5 points
  • No Python comments used when they are needed to clarify code: -5 points
  • The program doesn’t accept the date in the proper format (such as, the student erroneously requires the user to enter month, day and year separately instead of “day/month/year”): -10 points
  • For every failure of the sample test cases above: -5 points/error
  • If leap year is not considered in date validation: -10 points
  • There are three minimally required functions, -7 points/each otherwise:
    • main()
    • A “date checker” function that returns True or False if the date is valid or invalid when given day, month, and year as a function parameter
    • A leap year function that returns True or False if the given year function parameter is a leap or non-leap year.
  • Bad use of if-elif-else statements, or faulty logic: -5 points/each
Extra Credit:
  • Extra credit can be given for each use of exception handling. The use of exception handling must be appropriate for the context of what your program is doing and it has to be clearly commented. +5 points/each use
I will allow you to add something creative and interesting to your program for extra credit. Your extra credit additions needs to be relevant to the techniques we are learning. You are not guaranteed to receive extra credit, it will be up to the lab TA to decide. If your extra credit code is not clearly documented using comments, you risk losing points instead of receiving bonuses.

Note: Extra credit is added your normal submission file, do not submit a second file. Extra credit supersedes any of the above grading rubric if it conflicts.

Note 2: There may be additional criteria for grading, this is just a summary of the major rubric items.