Open main menu

CDOT Wiki β

Changes

Rchan sandbox

1,335 bytes added, 15:20, 2 November 2019
Part 1 - Simple Object Class with external functions
:*Date object from '''OPS435 Assignment 1'''
=Investigation 1I: Objects and Functions=
== Part 1 - Simple Object Class with external functions ==
</source>
:'''Perform the following steps:'''
:# 1. Download or create the above Pythone script '''lab7a.py''' in your ~/ops435/lab7 directory. :# 2. Create a new Python script named '''lab7a1.py''' in the lab7 directory:
<source lang="bash">
cd ~/ops435/lab7
vi ~/ops435/lab7/lab7a1.py
</source>
:# 3. Place the following content inside the new python file '''lab7a1.py''' and save it:<source lang="python">
#!/usr/bin/env python3
# Student ID: [seneca_id]
print(ft(t3),'+',ft(td),'-->',ft(tsum3))
</source>
:4. The above python script '''lab7a1.py''' should produce the following output when executed:<source lang="bash">
[rchan@centos7 lab7]$ python3 lab7a1.py
08:00:00 + 00:50:00 --> 08:50:00
08:55:00 + 00:50:00 --> 08:105:00
09:50:00 + 00:50:00 --> 09:100:00
</source>
:5 If you pay a little bit attention on the outputs, you should notice that the sum_times() function did not carry 60 minutes over to hour. It also will not carry 60 seconds over to minute.
:6 To fix that problem, perform the following:
::(a) Edit the file '''lab7a.py''' and modify the function sum_times(). Add code to check the values of the time object's three attributes. If the value of the minute attribute is more than 60, carry it over to the hour until it is less than 60. Do the same for the value of the second attribute.
::(b) Save the file.
:7. Download the checking script and check your work. Enter the following commands from the bash shell.<source lang="bash">
cd ~/ops435/lab7/
pwd #confirm that you are in the right directory
ls CheckLab7.py || wget https://ict.senecacollege.ca/~raymond.chan/ops435/labs/LabCheckScripts/CheckLab7.py
python3 ./CheckLab7.py -f -v lab7a
</source>
:8. Before proceeding, make certain that you identify all errors in lab7a.py. When the checking script tells you everything is OK - proceed to the next step.
<br><br>
1,760
edits