Open main menu

CDOT Wiki β

Changes

OPS445 Online Lab7

34 bytes added, 08:54, 13 March 2022
m
Part 1 - Classes and Methods for our Time objects
def sum_times(self, t2):
"""Add two time objests and return the sum."""
sum = """Change this external functions to become object methods for our Timeobject (0,0,0) self_sec = self.time_to_sec() t2_sec = t2refer to lab7c.time_to_sec() sum = sec_to_time(self_sec + t2_secpy)"""
return sum
def change_time(self, seconds):
time_seconds = self"""Change this external functions to become object methods for our Time object (refer to lab7c.time_to_sec(py) nt = sec_to_time(time_seconds + seconds) self.hour, self.minute, self.second = nt.hour, nt.minute, nt.second """
return None
</source>
: Please notice that the function named sec_to_time() did not get moved under the class block. It remains as an external function.
:1. Create a new python file and name it as '''lab7d.py''' and , place the code listed above in it, and change '''sum_times()''' and '''change_time()''' functions from lab7c.py to become object methods for our Time object.
:2. Save the file, and test the new time object in an interactive Python shell: <source lang="bash">
[rchan@centos7 lab7]$ python3
572
edits