Changes

Jump to: navigation, search

OPS445 Online Lab7

257 bytes removed, 06:19, 13 March 2022
m
Part 2 - Pure Function and Modifiers
</source>
:7. The result is not correct! So we have to modify and update the change_time() function so that it can handle positive and negative value correctly. The following steps are necessary:
::(a) We must first add code to check on the '''second''' attribute of the time object to make sure that it is not less than zero. If it is, we must borrow one from the '''minute''' attribute and add 60 to the '''second''' attribute. We have to repeat this checking until the '''second''' attribute is no long longer less than zero.<source lang="python"> while time.second < 0: time.minute -= 1 time.second += 60</source>::(b) We then have to add code to check on the '''minute''' attribute. If it is less than zero, we must borrow 1 from the 'hour' attribute and add 60 to the '''minute''' attribute. We have to repeat this checking until the '''minute''' attribute is no long longer less than zero.<source lang="python"> while time.minute < 0: time.hour -= 1 time.minute += 60</source>:8. After updating the change_time() function with the above additional codetasks, save the file and test it again in a Python interactive shell by importing the new version of the function.<source lang='bash'>
[rchan@centos7 lab7]$ python3
Python 3.4.9 (default, Aug 14 2018, 21:28:57)
572
edits

Navigation menu