Changes

Jump to: navigation, search

OPS435 Python3 Assignment 1

289 bytes added, 19:34, 29 January 2020
Create a private repository on github.com under your account by cloning the sample repo
== Authorship Declaration ==
All your Python code for this assignment must be placed in a <font color='red'><b><u>single source python file</u></b></font>. Please include the following declaration <b><u>as part of the docstring</u></b> in your Python source code file (replace "Student Name" with your own name):
<source>OPS435 Assignment 1 - Fall 2019Winter 2020
Program: a1_[student_id].py (replace student_id with your Seneca User name)
Author: "Student Name"
== Tests and Test results ==
You must name your python 3 script as <code>a1_[Student_id].py</code>. The following examples assumes that the student_id is rchan.The script should accept two command line arguments, the first one is the date in "YYYY/-MM/-DD" 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. There is an optional flag called --step which can be provided at the command line that makes the program print out all dates until the target date. If the "YYYY/-MM/-DD" 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 examples:* <b><code>python3 a1_rchan.py 2019/-01/-01 1</code></b>, and the output should be<br /> 2019/-01/-02* <b><code>python3 a1_rchan.py 2019/-01/-01 -1</code></b>, and the output should be<br /> 2018/-12/-31* <b><code>python3 a1_rchan.py 2019/-01/-01 2</code></b>, and the output should be<br /> 2019/-01/-03* <b><code>python3 a1_rchan.py --step 2019/-01/-01 3</code></b>, and the output should be<br /> 2019/-01/-02 2019/-01/-03 2019/-01/-04* <b><code>python3 a1_rchan.py 2018/-07/-01 500</code></b>, and the output should be<br /> 2019/-11/-13* <b><code>python3 a1_rchan.py 2018/-99/-01 2</code></b>, and the output should be<br />
Error: wrong month entered
* <b><code>python3 a1_rchan.py 2018/-01/-99 2</code></b>, and the output should be<br />
Error: wrong day entered
* <b><code>python3 a1_rchan.py 2018 2</code></b>, and the output should be<br />
If there is too few or too many command line arguments given, display the proper usage:
* <code>Usage: a1_rchan.py [--step] YYYY/-MM/-DD +/-n</code>
== 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 "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.
=== 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)
to_month = tmp_month + 0
next_date = str(year)+"/-"+str(to_month).zfill(2)+"/-"+str(to_day).zfill(2)
return next_date
= Bonus task =
There is 10% bonus if your script can also 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 by cloning the sample repo==* clone the repository https://github.com/rayfreeping/ops435-a1 for useful resource, sample code and test scripts for this assignment.* name the cloned repository under your github account as 'ops435-a1'
* invite 'rayfreeping' as one of the collaborator to your 'ops435-a1' repository
* use this repository for developing the and keeping track of the following text/source code files:
** the python script for assignment 1 named "a1_[seneca-id].py"
** the test results produce by the assignment checking script "checkA1.py". Name it as a1_results.txt
* double check and make sure your ops435-a1 on github is configured as a private repository.
= Rubric =
1,760
edits

Navigation menu