Changes

Jump to: navigation, search

OPS435 Python3 Assignment 2P

4,367 bytes removed, 23:44, 7 November 2019
no edit summary
>>>
</source>
 
== Script structure and sample template ==
Your code should all be in a single python file with at least the functions mentioned above: dbda(), after(), and before(). To earn the maximum mark, you should also create additional functions into your algorithm, e.g.: leap_year(), days_in_mon, valid_date(), usage(), etc
 
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 "YYYY/MM/DD" 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 "YYYY/MM/DD" format and return the date of the previous day in the same format.
* The after() function will take a date in "YYYY/MM/DD" 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 "YYYY/MM/DD" 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.
<pre>
#!/usr/sbin/env python3
''' docstring
'''
import ...
 
def after(today):
....
return next_day
 
def before(today):
....
return previous_day
 
....
 
def dbda(date,days):
...
setup loop:
call after() or before() as appropriate
return target_day
 
if __name__ == "__main__":
 
.. processing command line arguments ..
.. call dbda()
...
.. output the result
 
</pre>
 
=== Sample code for the after() function ===
<pre>
# Return the date in YYYY/MM/DD after the given day
#
def after(today):
if len(today) != 10:
return '0000/00/00'
else:
str_year, str_month, str_day = 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(year)+"/"+str(to_month).zfill(2)+"/"+str(to_day).zfill(2)
return next_date
</pre>
 
= Normal task =
Your script must be able to take two dates both in "YYYY/MM/DD" format and output the number of days between the given two dates.
e.g.
* Calculate the number of days between "2018/03/01" and "2019/03/01"
python3 a1_rchan.py 2018/03/01 2019/03/01
365
* Calculate the number of days between "2019/03/01" and "2018/03/01"
python3 a1_rchan.py 2019/03/01 2018/03/01
365
= Deliverable =
== Create a private repository on github.com under your account ==
* name the repository as 'ops435-a1'a2p* invite 'rayfreeping' as one of the collaborator to your 'ops435-a1a2p' repository
* use this repository for developing the and keeping track of the following text/source code files:
** the algorithm for assignment 1 named "a1_algorithmThe readme.md file to show your progress. Add entry whenever you update any files in this repository.txt"** the python script for assignment 1 class definition named "a1_[seneca-id]a2_class.py"** the test results produce by the assignment checking script "checkA1checkA2P.py". Name it as a1_resultsa2p_results.txt
= Rubric =
| Program Authorship Declaration ||5 ||
|-
| Program usage || 5 |||-| Program Options --step || 5 |||-| after() function class block || 5 ||
|-
| before__init__() function method || 15 10 ||
|-
| dbda__str__() function method || 10 5 ||
|-
| script level docstring __repr() method || 5 ||
|-
| leap_year() function '+' operator || 5 10 ||
|-
| valid_date() function '-' operator || 5 10 ||
|-
| days_in_montomorrow() function method || 5 10 ||
|-
| usageyesterday() function method || 5 10 ||
|-
| Algorithm docstring ||15||
|-
| github.com repository||15||
Please submit the following files to blackboard by the due date:
* your algorithm (step-by-step instruction for solving the computation problem for this assignment in the English language), name the file as 'a1_algorithm.txt'* your python script, name the file as 'a1_[seneca-id]a2_class.py'* the output of the checking script checkA1checkA2P.py, name the file as 'a1_resultsa2p_results.txt'* the 'git log' output for your own repository 'ops435-a1a2p' on github.com, name the file as 'a1_gitloga2p_gitlog.txt'
1,760
edits

Navigation menu