Open main menu

CDOT Wiki β

Changes

OPS445 Online Assignment 1

9 bytes added, 16:01, 4 October 2021
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 "YYYYDD-MM-DDYYYY" 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 "YYYYDD-MM-DDYYYY" format and return the date of the previous day in the same format.* The after() function will take a date in "YYYYDD-MM-DDYYYY" 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 "YYYYDD-MM-DDYYYY" 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 ===
<pre>
# Return the date in YYYYDD-MM-DD YYYY after the given day
#
def after(today):
if len(today) != 10:
return '000000-00-000000'
else:
str_yearstr_day, str_month, str_day str_year = today.split('-')
year = int(str_year)
month = int(str_month)
to_month = tmp_month + 0
next_date = str(yearto_day).zfill(2)+"-"+str(to_month).zfill(2)+"-"+str(to_dayyear).zfill(2)
return next_date