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)
I’m OK with you allowing leading zeros for the month, or day. This is optional, however.
  • 03/04/2017 — (valid)
  • 07/22/2019 — (valid)
  • 00/12/1234 — (not valid)

Generally speaking, I want to see the following structure in your program. This encourages “separation 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).

Output

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

or

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

Your file is required to be named lab_decision_control.py.

Please read and follow the Submission Requirements to avoid point deductions specified below.

Grading

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

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

Grading Rubric
Type Description Point Loss (Max)
  [General]  
SyntaxError Exceptions A program that doesn’t even start due to syntax errors. -30
Docstrings Missing proper lab header (e.g. no name, lab section, etc) -10
main() Your program should have main() as the first-called function -10
PEP 8 Style Egregious problems with your code styling -10
Incorrect Filename Follow the submission instructions -5
Commenting Insufficient or excessive comments -5
  [Lab Specific]  
Date Input Date should be in lab-described format (leading zeroes, optional) -10
Test Cases Testing fails against the example dates -3/each
Leap Year Leap year is not considered in date validation -7
Required functions There are three minimally required functions (main(), a “date check” and “leap year” functions) -7/each
Boolean return values Your “date check” and “leap year” functions must returns True or False -5/each
Boolean Expressions Bad use of if-elif-else statements, or faulty logic -5/each

Extra Credit

Extra credit work must be submitted in what would be your original submission file for the assignment. All extra credit code must be clearly commented in order to receive any points.

  • +5 points Extra credit can be given for the proper 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.