1,760
edits
Changes
→Part 3 - Another approach to perform operation on time objects
...
...
</source>
:1. Make a copy of lab7b.py and name it as lab7c.py in the ~/ops435/lab7 directory:<source lang="bash">
cd ~/ops435/lab7
cp lab7b.py lab7c.py
</source>
:2. Add the above two new functions: time_to_sec() and sec_to_time() to lab7c.py after the change_time() function.
:3. Save the file, and test the two function in an Python interactive shell:<source lang="bash">
[rchan@centos7 lab7]$ python3
Python 3.4.9 (default, Aug 14 2018, 21:28:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from lab7c import *
>>> t1 = Time(9,50,0)
>>> sec_t1 = time_to_sec(t1)
>>> sec_t1
35400
>>> t1_sec = sec_to_time(sec_t1)
>>> t1_sec
<lab7c.Time object at 0x7f89f656e048>
>>> format_time(t1_sec)
'09:50:00'
>>>
</source>
:4. You should get the same result as shown above. If not, please troubleshoot and fix any errors.
:5. Edit your lab7c.py again. Modify the other two functions: sum_times() and change_time() to use the two new functions to perform the computation operation.
:6. Create a new Python script named '''lab7c1.py''' with the following content:<source lang="python">
</source>