You will be graded partly on the quality of your Github commits. Professionals generally follow these guidelines:
-
commit their code after every significant change,
-
the code should run without errors after each commit, and
-
every commit has a descriptive commit message.
These guidelines are not always possible, but you will be expected to follow these guidelines as much as possible. Break your problem into smaller pieces, and work iteratively to solve each small problem. Test your code after each small change you make, and address errors as soon as they arise. It will make your life easier!
Tests and Test results
You must name your python 3 script as
assign1.py. The script should accept two command line arguments, the first one is the date in “DD-MM-YYYY” format, and the second one is the number of day from the given date, a positive value indicates the number of days after the given date, and a negative value indicates the number of days before the given date. If the “DD-MM-YYYY” format is broken, your script should give an appropriate error message. Invalid months (>12) or invalid days of month(different for each month), should be detected and give appropriate error messages. For example:
-
python3 assign1.py 01-01-2019 1
, and the output should be
02-01-2019
-
python3 assign1.py 01-01-2019 -1
, and the output should be
31-12-2018
-
python3 assign1.py 01-06-2020 365
, and the output should be
01-06-2021
-
python3 assign1.py 01-01-2019 365
, and the output should be
01-01-2020
-
python3 assign1.py 01-01-2021 -366
, and the output should be
01-01-2020
-
python3 assign1.py 01-13-2018 1
, and the output should be
Error: wrong month entered
-
python3 assign1.py 99-01-2020 1
, and the output should be
Error: wrong day entered
-
python3 assign1.py 2018 2
, and the output should be
Error: wrong date entered
If there is too few or too many command line arguments given, display the proper usage:
-
Usage: assign1.py DD-MM-YYYY N
Script structure and sample template
The following is a brief description of each function:
-
The
dbda()
function should be the main function of your script. The dbda() function will take a date in “DD-MM-YYYY” format, a positive or negative integer, and return a date either before or after the given date according to the value of the given integer in the same format. Your dbda() function should delegate the actual calculation of the target date to either the after() function or the before() function.
-
The
before()
function will take a date in “DD-MM-YYYY” format and return the date of the previous day in the same format.
-
The
after()
function will take a date in “DD-MM-YYYY” format and return the date of the next day in the same format. Next paragraph is a sample python code for the after() function. To earn the maximum possible mark for the assignment, you should modify the sample after() function to make use of the days_in_mon() function.
-
The
leap_year()
function will take a year in “YYYY” format, and return True if the given year is a leap year, otherwise return False.
-
The
valid_date()
function will take a date in “DD-MM-YYYY” format, and return True if the given date is a valid date, otherwise return False plus an appropriate status message. The valid_date() function should make use of the days_in_mon() function.
-
The
days_in_mon()
function will take a year in “YYYY” format, and return a dictionary object which contains the total number of days in each month for the given year. The days_in_mon() function should make use of the leap_year() function.
-
The
usage()
function will take no argument and return a string describing the usage of the script.
Sample code for the after() function
# Return the date in DD-MM-YYYY after the given day # def after(today): if len(today)!= 10: return ’00-00-0000′ else: str_day, str_month, str_year = today.split(‘-‘) year = int(str_year) month = int(str_month) day = int(str_day) lyear = year% 4 if lyear == 0: feb_max = 29 # this is a leap year else: feb_max = 28 # this is not a leap year lyear = year% 100 if lyear == 0: feb_max = 28 # this is not a leap year lyear = year% 400 if lyear == 0: feb_max = 29 # this is a leap year tmp_day = day + 1 # next day mon_max = { 1:31, 2:feb_max, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31} if tmp_day > mon_max[month]: to_day = tmp_day% mon_max[month] # if tmp_day > this month’s max, reset to 1 tmp_month = month + 1 else: to_day = tmp_day tmp_month = month + 0 if tmp_month > 12: to_month = 1 year = year + 1 else: to_month = tmp_month + 0 next_date = str(to_day).zfill(2)+”-“+str(to_month).zfill(2)+”-“+str(year).zfill(2) return next_date
Rubric
Task |
Maximum mark |
Actual mark |
Program Authorship Declaration |
5 | |
Program usage |
5 |
|
after() function |
5 |
|
before() function |
10 |
|
dbda() function |
10 |
|
script level docstring |
5 |
|
leap_year() function |
5 |
|
valid_date() function |
5 |
|
check script results |
15 |
|
First Milestone |
10 | |
Second Milestone |
10 | |
github.com repository |
15 | |
Total |
100 |
Due Date and Final Submission requirement
Check with your professor for the due date for your section.
Please submit the following files by the due date:
-
your algorithm document, named as ‘algorithm_youruserid.txt’, to Blackboard. This is your first milestone.
-
your python script, named as ‘assign1.py’, should be included in your repository, and also
submitted to Blackboard.
-
the output of the checking script ‘CheckA1.py -f -v &>’, named as ‘a1_output.txt’, should be included in your repository.